Java的如何去除字符串回车(HEX 0A)? [英] Java How to remove carriage return (HEX 0A) from String?

查看:706
本文介绍了Java的如何去除字符串回车(HEX 0A)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果一个特定的字符串包含换行符是无形的(不是\\ n,而是为0A十六进制的,因为这个值是从数据库中传下来的),我怎么能终日啃食它扔掉?将阿帕奇的Chomp帮助?

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?

<一个href=\"http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html#chomp(java.lang.String\" rel=\"nofollow\">http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html#chomp(java.lang.String)

从数据库返回的文本的十六进制形式为5761 6920 4D61 6E0D 0A

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.

推荐答案

您可以使用常规的前pression

You can use a regular expression

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

这篇关于Java的如何去除字符串回车(HEX 0A)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆