Reputation: 397
In my application I am displaying text from database in a textview. The text contains '\r\n'. So I replaced '\r\n' with empty i.e with ' '.
My code:
String myString = listItem.gettextdata().replace("\r\n", " ");
But still the text is displaying with \r\n....where I went wrong? Please help me regarding this....
Thanks in advance
Upvotes: 0
Views: 1234
Reputation: 109237
Simply:
String str;
str = "hello\r\njava\r\nbook";
str = str.replaceAll("(\\r|\\n)", " ");
System.out.println(str);
Or
str = str.replaceAll("\\r\\n", " ");
Upvotes: 1
Reputation: 68177
try this:
String myString = listItem.gettextdata().replaceAll("[\r\n]", "");
Upvotes: 0
Reputation: 3194
What if you try a .toString() after gettestdate():
String myString = listItem.gettextdata().toString().replace("\r\n", " ");
Upvotes: 1
Reputation: 5825
Is this a case where you have to escape the backslash character, i.e.
String myString = listItem.gettextdata().replace("\\\\r\\\\n", " ");
Upvotes: 5