小编Iwa*_*ing的帖子

Java:将所有'替换为字符串中的'

我需要在字符串中转义所有引号('),因此它变为\'

我尝试过使用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
Run Code Online (Sandbox Code Playgroud)

我真的被困在这里,希望有人能在这里帮助我.

谢谢,

我要

java regex string replaceall

21
推荐指数
3
解决办法
11万
查看次数

标签 统计

java ×1

regex ×1

replaceall ×1

string ×1