Java How to remove carriage return (HEX 0A) from String?

ぃ、小莉子 提交于 2019-12-11 04:36:18

问题


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?

http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html#chomp(java.lang.String)

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.


回答1:


You can use a regular expression

String text = "Hello\r\nThere\r\n";
String shortText = text.replaceAll("\r", "");


来源:https://stackoverflow.com/questions/6870858/java-how-to-remove-carriage-return-hex-0a-from-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!