Java Escape character classification

Source: Internet
Author: User

One: the Java escape character comparison table (character comparison chart on the Web many, but do not remember, there is a simpler way, see (iv) Analysis of the results; also remember (v) the 3 special characters and 5 control characters)

Escape of points:. ==> u002e
Escape of Dollar sign: $ ==> u0024
The escape of the symbol of the exponent: ^ ==> u005e
Escape of opening curly brace: {==> u007b
Escape of the left parenthesis: [==> u005b
Escape of the Left parenthesis: (==> u0028
Escape of vertical bars: | ==> u007c
Escape of Right parenthesis:) ==> u0029
Escape of asterisks: * ==> u002a
Escape of the plus sign: + ==> u002b
Escape of question marks:? ==> u003f

Anti-slash escape: ==> u005c

Second: Specific test experiment

(1) Non-intended code (results are not expected)

String str2= "A$b$c";  String strs[]=str2.split ("$");  for (String str:strs) {      System.out.println (str);  }  

Result: A, B, C need to be escaped to be like:


(2) Expected code (expected result)
String str2= "A$b$c";  String strs[]=str2.split ("\\u0024"); This sentence is equivalent to split ("\ \"), and so on and so on | Split ("u007c") or split ("\\|") for (String str:strs) {      System.out.println (str);  }  
Three: The complete code:
public static void Main (string[] args) {
System.out.println ("****\\\\");
String str = "A\\B\\B\\C.CSV|AAAAA";
string[] chars = Str.split ("\\\\");
string[] FileName = chars[3].split ("\ \"); /u002e
string[] tmp = Chars[3].split ("\\u007c");//\\u007c
for (String cha:chars) {
System.out.println (CHA);
}
System.out.println (Filename[0]);
System.out.println (tmp[1]);

}

Four: summary

(1) such as | Split ("u007c") or split ("\\|");

(2) The Java escape character list can be escaped according to the above line, that is, String expr = "\ \ corresponding character"; Instead of remembering its corresponding 16 binary sequence.


V: Knowledge Supplement (3 special characters and 5 control characters, in fact, similar to the character comparison table, the double slash \ \ Corresponding character changed to a single slash \ corresponding character )

1. Eight binary escape sequence: \ + 1 to 3 bit 5 digits; Range ' \000 ' ~ ' \377 '
: null character
2.Unicode Escape Character: \u + four hexadecimal digits; 0~65535
\u0000: null character
3. Special characters: 3
\ ": Double quotation marks
\ ': Single quote
\ \: Backslash
4. Control characters: 5
\ ' Single quote character
\ \ backslash Character
\ r Enter
\ nthe line break
\f Paper Change page
\ t transverse jump lattice
\b Backspace

Java Escape character classification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.