Java:将字符串中的所有 ' 替换为 \'
2022-09-01 20:03:16
我需要转义字符串中的所有引号('),所以它变成了\'
我尝试过使用 replaceAll,但它不做任何事情。由于某种原因,我无法让正则表达式工作。
我正在尝试
String s = "You'll be totally awesome, I'm really terrible";
String shouldBecome = "You\'ll be totally awesome, I\'m really terrible";
s = s.replaceAll("'","\\'"); // Doesn't do anything
s = s.replaceAll("\'","\\'"); // Doesn't do anything
s = s.replaceAll("\\'","\\'"); // Doesn't do anything
我真的被困在这里,希望有人能在这里帮助我。
谢谢
伊万