Amrutha Saj
Amrutha Saj

Reputation: 1428

want to print “\n” sign without getting a new line

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

Answers (3)

letsCode
letsCode

Reputation: 3046

In Code

String string = "abcd\nddsda";
System.out.println(string.replace("\n","\\n"));

Upvotes: 0

Sushin Pv
Sushin Pv

Reputation: 1894

Try this

<string name="example"><![CDATA[ Hello\nworld ]]></string>

Upvotes: -1

Ben P.
Ben P.

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

Related Questions