我不是在这里要求优雅,但我 认为 它可以满足您的要求(如果我误会了,请纠正我):
public static void main(String[] args){ String example = "Hello, I'm" here"; example = example.replaceAll("'", "\\'"); example = example.replaceAll(""", "\\""); System.out.println(example);}输出
Hello, I'm" here



