I found that there are still some things in my mind, and there is no concept after a period of time, so I posted them so as not to forget...
When splitting a string, an exception is reported when \ is used to split the string.
Public class main {/*** @ Param ARGs */public static void main (string [] ARGs) {string AA = "G: \ A \ BB \ cc.gif "; system. out. println (AA);/*** because it involves two layers, one is Java and the other is source code. * The regular expression needs to be escaped and \ is used to represent \; * In the source code of Java, escape characters must be expressed \. * Therefore, when they are accumulated, they must be four diagonal lines \. In this way, the Java escape character is \\, and \ is escaped in the Regular Expression and then \ can be matched * A little round, haha ~ */String [] xx = AA. Split ("\"); For (string cell: XX) {system. Out. println (cell );}}}
The exception is as follows:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1\ ^at java.util.regex.Pattern.error(Pattern.java:1713)at java.util.regex.Pattern.compile(Pattern.java:1466)at java.util.regex.Pattern.<init>(Pattern.java:1133)at java.util.regex.Pattern.compile(Pattern.java:823)at java.lang.String.split(String.java:2292)at java.lang.String.split(String.java:2334)at cn.osl.businessagent.test.Main.main(Main.java:18)
In this case, use \\\\
Public class main {/*** @ Param ARGs */public static void main (string [] ARGs) {string AA = "G: \ A \ BB \ cc.gif "; system. out. println (AA);/*** because it involves two layers, one is Java and the other is source code. * The regular expression needs to be escaped and \ is used to represent \; * In the source code of Java, escape characters must be expressed \. * Therefore, when they are accumulated, they must be four diagonal lines \. In this way, the Java escape character is \\, and \ is escaped in the Regular Expression and then \ can be matched * A little round, haha ~ */String [] xx = AA. Split ("\\\\"); For (string cell: XX) {system. Out. println (cell );}}}
Output result:
g:\a\bb\cc.gifg:abbcc.gif