Akh*_*ila 5 java special-characters
我需要用值替换字符串中的{Name}值.
我们怎样才能更换特殊字符{和}?
我试过这个:
str.replaceAll("{Name}","A");
Run Code Online (Sandbox Code Playgroud)
但如果我们有特殊字符,这不起作用.
T.J*_*der 14
使用replace而不是replaceAll,因为replace不期望和解析正则表达式.
示例:( 实时复印件)
String str = "Here it is: {Name} And again: {Name}";
System.out.println("Before: " + str);
str = str.replace("{Name}","A");
System.out.println("After: " + str);
Run Code Online (Sandbox Code Playgroud)
输出:
Before: Here it is: {Name} And again: {Name}
After: Here it is: A And again: A