I have a scenario where I need to format a string into an array to display it in a different way to the user. So, when I get an escape character (for a new line) \n I need to add that as a separate array item.
Example string : sampe\nanother sample HERE\n\n\nfinal
Should be formatted to ["sample", "another sample", "", "", "final"]
Here the empty strings in the array are for the new lines. How can I achieve this ?
EDIT : I have a special scenario if something in between ${, } that also should be considers as a new array item.
eg : "sampe\n${abc}another sample HERE\n\n\nfinal"
in this case, this should be the array
["sample", "${abc}", "another sample", "", "", "final",]
So, this should also be achievable . Currently without considering the escape characters I'm looping through the array to detect ${ and } to do this. So, with the \n how can I get this work