Regex with replaceAll.
public class Main
{
public static void main(final String[] argv)
{
String str;
str = "hello
java
book";
str = str.replaceAll("(\r|\n)", "");
System.out.println(str);
}
}
If you only want to remove
when they are pairs (the above code removes either
or
) do this instead:
str = str.replaceAll("\r\n", "");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…