Why does .split(“\\”) generate an exception?

前端 未结 5 1446
死守一世寂寞
死守一世寂寞 2021-01-25 03:35

I have a String representing a directory, where \\ is used to separate folders. I want to split based on \"\\\\\":

String address = \"C         


        
5条回答
  •  一生所求
    2021-01-25 04:27

    You need to use \\\\ instead of \\.

    The backslash(\) is an escape character in Java Strings.If you want to use backslash as a literal you have to type \\\\ ,as \ is also a escape character in regular expressions.

    For more details click here

提交回复
热议问题