Eight backslashes required to replace single backslash with double backslashes?

后端 未结 6 508
借酒劲吻你
借酒劲吻你 2021-01-18 09:37

This is a \"what the heck is going on here\" question. I don\'t actually need a solution.

I had to replace all single backslashes in a String with double backslashe

6条回答
  •  误落风尘
    2021-01-18 10:20

    It's easier if you use replace("\\","\\\\") (String.replace takes literal strings and is more efficient when it's all literal)

    or you can ensure correctness through the Pattern.quote and Matcher.quoteReplacement functions

提交回复
热议问题