how to split the string in java

后端 未结 10 1686
梦如初夏
梦如初夏 2020-12-11 10:44

how to split the string in java in Windows? I used Eg.

String directory=\"C:\\home\\public\\folder\";
String [] dir=direct.split(\"\\\");
         


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 11:36

    You need to escape it.

    String [] dir=direct.split("\\\\");
    

    Edit: or Use Pattern.quote method.

     String [] dir=direct.split(Pattern.quote("\\"))
    

提交回复
热议问题