请教如何截掉中文字符串后面的回车符 如:“测试字符串-这个字符串后面有回车否,怎么去掉?”; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.out.print("测试字符串-这个字符串后面有回车否,怎么去掉?\n".replaceAll("\n*$", "")); System.out.println("ok"); 这样更好点System.out.print("测试字符串-这个字符串后面有回车否,怎么去掉?\n\r".replaceAll("[\r\n]*$", "")); System.out.println("ok"); public class Test { public static void main(String[] args) { String src = "测试字符串-这个字符串后面有回车否,怎么去掉?\r\n"; System.out.println("-----------------"); System.out.println(src); System.out.println("-----------------"); System.out.println(src.trim()); System.out.println("-----------------"); }}输出:-----------------测试字符串-这个字符串后面有回车否,怎么去掉?���-----------------测试字符串-这个字符串后面有回车否,怎么去掉?���----------------- "测试字符串-这个字符串后面有回车否,怎么去掉?\r\n".trim()即可 输入的文本如果保存在String类型的变量text中,那可以这样text = text.replaceAll("[\r\n]*", ""));不知道理解得对不对 兄台,,不是啊 !如下:源:String string = "this is test-string";目的:String string = "this is test-string"; 兄台,,不是啊 !如下:源:[/color]String string = "this is test-string";目的:[/color]String string = "this is test-string"; 兄台,,不是啊 !如下:源:String string = "this is test-string";目的:String string = "this is test-string"; lz要什么意思啊? 这个?String string = "this is test-string";敲下回车String string = "this is test-stri"+ "ng"; 请问一下,如何改变JTree选中节点的图标? 100分求解一个问题 JScrollBar如何 自动滚动到最下面 初学java 请教一个比较幼稚的问题 为什么不能运行? 如何将tomcat8080端口改成8090? 这样的错误是由于什么原因引起的? 有一个关于javax.mail 发邮件 使用 代理服务器的问题 代理服务器需要密码 请问:如何通过JAVA程序访问Web页面? 请问一个关于Interface的问题 初学java,有个问题想请教各位 异常继承自定义用户信息问题
System.out.println("ok");
System.out.print("测试字符串-这个字符串后面有回车否,怎么去掉?\n\r".replaceAll("[\r\n]*$", ""));
System.out.println("ok");
public class Test {
public static void main(String[] args) {
String src = "测试字符串-这个字符串后面有回车否,怎么去掉?\r\n";
System.out.println("-----------------");
System.out.println(src);
System.out.println("-----------------");
System.out.println(src.trim());
System.out.println("-----------------");
}
}输出:
-----------------
测试字符串-这个字符串后面有回车否,怎么去掉?���-----------------
测试字符串-这个字符串后面有回车否,怎么去掉?���
-----------------
text = text.replaceAll("[\r\n]*", ""));不知道理解得对不对
兄台,,不是啊 !如下:
源:String string = "this is test-stri
ng";
目的:String string = "this is test-string";
兄台,,不是啊 !如下:
源:[/color]String string = "this is test-stri
ng";
目的:[/color]String string = "this is test-string";
源:String string = "this is test-stri
ng";
目的:String string = "this is test-string";
什么意思啊?
这个?
String string = "this is test-string";
敲下回车
String string = "this is test-stri"+
"ng";