如何删除字符串中的换行符呢?
下文笔者讲述使用java代码删除字符串中换行符的方法分享,如下所示:
删除换行符的方法分享
实现思路:
借助String的replace()方法即可删除字符串中的换行符
String str ="******";
str = str.replace("\n", "").replace("\r", "");
例:删除换行符的方法分享
package com.java265.other;
public class Test {
/*
* java265.com 删除换行符的示例分享
*/
public static void main(String[] args) throws Exception {
String s = "我拥有换行符号\n换行";
System.out.println("==================");
System.out.println(s);
System.out.println("==================");
// 剔除换行符
s = s.replace("\n", "").replace("\r", "");
System.out.println(s);
System.out.println("==================");
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


