0

I have a string in my strings.xml in which there is "\n" sign between them

<string name="example">Hello\nworld</string>

What can I do to get the "\n" sign instead of a new line?

Amrutha Saj
  • 1,408
  • 16
  • 35

3 Answers3

5

Special characters in string resources can be backslash-escaped. So if you want to display "Hello\nworld" then you should make your string be hello\\nworld (notice the double backslash).

Ben P.
  • 52,661
  • 6
  • 95
  • 123
0

In Code

String string = "abcd\nddsda";
System.out.println(string.replace("\n","\\n"));
letsCode
  • 2,774
  • 1
  • 13
  • 37
-1

Try this

<string name="example"><![CDATA[ Hello\nworld ]]></string>
Sushin Pv
  • 1,826
  • 3
  • 22
  • 36