'Java How to remove carriage return (HEX 0A) from String?
If a particular String contains a newline character that is invisible (not \n but is 0A in hexadecimal because this value is passed down from the database), how can i able to chomp it away? Will Apache Chomp help?
The hex form of the text returned from the database is "5761 6920 4D61 6E0D 0A"
It translates to "Wai Man" with a carriage return.
Solution 1:[1]
You can use a regular expression
String text = "Hello\r\nThere\r\n";
String shortText = text.replaceAll("\r", "");
Solution 2:[2]
This is what I did and it worked for me:
input_data.replaceAll("\\xC2"," ").replaceAll("\\xA0"," ")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Peter Lawrey |
| Solution 2 | procrastinator |
