How to replace “ \ ” with “ \\ ” in java

前端 未结 4 558
傲寒
傲寒 2020-11-29 10:35

I tried to break the string into arrays and replace \\ with \\\\ , but couldn\'t do it, also I tried String.replaceAll something like this (&

4条回答
  •  醉酒成梦
    2020-11-29 10:46

    You could use replaceAll:

    String escaped = original.replaceAll("\\\\", "\\\\\\\\");
    

提交回复
热议问题