[英]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.