how to split the string in java

后端 未结 10 1706
梦如初夏
梦如初夏 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:14

    split() function in Java accepts regular expressions. So, what you exactly need to do is to escape the backslash character twice:

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

    One for Java, and one for regular expressions.

提交回复
热议问题