将 Java 字符串中的 #
替换为 \u0023
,如下所示:
{subjectCategory:"s123", subjectId:"111222333", content:"test #comment999", ownerId:"111", ownerName:"tester"}
String.replace("#","\\u0023");
我已经尝试过上述功能,但似乎不起作用。
最佳答案
您需要用另一个反斜杠转义反斜杠:
string = string.replace("#", "\\u0023");
测试:
String s = "hello # world";
s = s.replace("#","\\u0023");
System.out.println(s); // prints hello \u0023 world
关于java - 在 Java 字符串中将 # 替换为\u0023,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11791077/