I got an issue that I'm not able to solve
I have a paragraph that contains some keywords need to be replaced with new values which are stored in an array
Example:
Paragraph: "My most favorite fruit is [0], but I also like [1] and [3]"
Array: fruits = ["Banana", "Orange", "Apple", "Grape"]
My expectation is: My most favorite fruit is Banana, but I also like Orange and Grape
Could you help me to find a solution for this?
I have tried to convert my sentence into Array of String like this:
["My most favorite fruit is ","[0]",", but I also like ","[1]"," and ","[3]"]
After that, I replace [0] to 0, I got this:
["My most favorite fruit is ","0",", but I also like ","1"," and ","3"]
I tend to replace 0, 1, and 3 in above array into value of fruits[0], fruits[1], fruits[3] then convert that array into a completed string
But I think it's not the best solution, because if I got an input sentence like this: "2[2]" then I will receive the output is AppleApple, whereas the Expectation is 2Apple