Java intercept backslash ReplaceAll and split ("\") Problem resolution
Xxx.split ("\ \") is obviously not getting the results you want.
Correct method
Xxx.split ("\\\\");
The reasons are as follows:
In Java to deal with some path-related problems, such as to remove the file name of Internet Explorer upload file, because IE will be the entire file path as file name upload, need to use java.lang.String in the ReplaceAll or split to deal with. Such as:
The upload file path is: C:\Documents and Settings\collin\my documents\111-lazyloading.gif, to remove the file name: 111-lazyloading.gif. OK
String temp[] = Name.split ("\\\\");
if (Temp.length > 1) {
name = Temp[temp.length-1];
}
The regex is \\\\ because \ \ is represented in Java and \ \ is also represented in the regex, so when \\\\ resolves to regex it is \ \.
Because File.separator is a slash "/" in Unix, the following code can handle all situations under Windows and UNIX:
Strin G temp[] = Name.replaceall ("\\\\", "/"). Split ("/");  
When you use split in Java to split special characters, you will find that you cannot achieve the results you want. Like what
Java code
- "1234567891^1234567890". Split ( "^") [1]  
An array subscript out-of-bounds exception is indicated, indicating that no split was successful at all. The reason, the original ^ is a special character, split parameter is a regular expression, so in order to let split identify special characters, you need to change the parameters to the regular, that is, before the parameter with "\ \" can be.
Java code
- "1234567891^1234567890". Split ("\\^") [1]
Java intercept backslash--java use split to split special characters