How to replace every line by \n

I have a TextField and bellow of the TextField there is a Card and Text as child,The child of the Card display the String that entered in TextField, I want to replace every line by \n, How can I do this?

Example:

Text entered :

Hello

World

result :

Hello

World

expected :

Hello\nWorld

Hey @Jyotigautam! I think you can resolve this issue if you replace every "\n" with "\\\\n".

Hope this helps!

I think you just need an extra slash. Or, you can use a raw string.
"Hello

World".replace(’\n’, r’\n’) should also work. Keep in mind your example seems to have two newlines.

2 Likes