Java: replaceAll doesn't work well with backslash?

前端 未结 9 1420
北荒
北荒 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:38

    jarPath = jarPath.replaceAll("\\\\\\\\xyz\\\\abc", "z:");
    

    For each '\' in your string you should put '\\' in the replaceAll method.

提交回复
热议问题