Java: replaceAll doesn't work well with backslash?

前端 未结 9 1408
北荒
北荒 2021-01-25 12:56

I\'m trying to replace the beginning of a string with backslashes to something else. For some weird reason the replaceAll function doesn\'t like backslashes.

Str         


        
9条回答
  •  粉色の甜心
    2021-01-25 13:43

    The replaceAll method uses regular expressions, which means that you have to escape slashes. In your case it might make sense to use String.replace instead:

    String jarPath = "\\\\xyz\\abc\\wtf\\lame\\";
    jarPath = jarPath.replace("\\\\xyz\\abc", "z:");
    

提交回复
热议问题