小编Kum*_*rsh的帖子

在尝试替换字符串中的字符时获取"

我想用"字符串替换^.

String str = "hello \"there";
System.out.println(str);
String str1 = str.replaceAll("\"", "^");
System.out.println(str1);
String str2= str1.replaceAll("^", "\"");
System.out.println(str2);
Run Code Online (Sandbox Code Playgroud)

输出是:

hello "there
hello ^there
"hello ^there
Run Code Online (Sandbox Code Playgroud)

为什么我"在字符串的开头和字符串^之间得到额外的

我期待:

hello "there
Run Code Online (Sandbox Code Playgroud)

java regex string replaceall

8
推荐指数
2
解决办法
410
查看次数

标签 统计

java ×1

regex ×1

replaceall ×1

string ×1