请问java怎么去掉字符串末尾的换行符,谢谢!

constantlylearn 2004-11-18 02:00:56
请问java怎么去掉字符串末尾的换行符,谢谢!
还有,下面语句居然报错Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

String old_str="aaa";
char[] new_str = old_str.toCharArray();
System.out.println(new_str[0]);
...全文
6691 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dreamno 2004-11-18
  • 打赏
  • 举报
回复
replaceAll("\\n","");
singinthesky 2004-11-18
  • 打赏
  • 举报
回复
1,去掉换行符用replaceAll("\n","");回车符是"\r";trim()用来去首尾的空格符
2,在我这里运行并无错
narilee 2004-11-18
  • 打赏
  • 举报
回复 1
去掉字符串末尾的换行符可以用trim()函数.
Lamplance 2004-11-18
  • 打赏
  • 举报
回复
恩,没有错误!
treeroot 2004-11-18
  • 打赏
  • 举报
回复 1
s=s.trim();
kevingn 2004-11-18
  • 打赏
  • 举报
回复
a
Press any key to continue...
并无错误

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧