[英]Unable to replace \\n with empty string using java
Trying to replace \\n from a String with "",
after removing the \\n the expected o/p would be: "This is not working ";
Tried samples :
String str = "This \\nis \\n\\nnot \\n\\nworking ";
str.replaceAll("\\n","");
您必须使用\\\\n
而不是\\n
。 这应该有效:
String str = "This \\nis \\n\\nnot \\n\\nworking ";
System.out.println(str.replaceAll("\\\\n",""));
您可以参考在线正则表达式生成器来探索更多模式。 这真的很有帮助!
同时我想下面的例子应该为你的用例服务:
public class RegularExpression {
public static void main(String[] args) {
String originalString = "This \\nis \\n\\nnot \\n\\nworking ";
String newString = originalString.replaceAll("\\\\n","");
System.out.println(newString);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.