Reputation: 1428
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?
Upvotes: 0
Views: 147
Reputation: 3046
In Code
String string = "abcd\nddsda";
System.out.println(string.replace("\n","\\n"));
Upvotes: 0
Reputation: 1894
Try this
<string name="example"><![CDATA[ Hello\nworld ]]></string>
Upvotes: -1
Reputation: 54204
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).
Upvotes: 5