all of the escape characters are preceded by ' \ '
Second character
0-9: Octal
u: is a Unicode turn, fixed length to 6-bit
Other: One of the b,t,n,f,r in the following letters, ", \
is not satisfied, a compilation error is generated.
of course, the provision of octal is also to be compatible with the C language.
The
B,t,n,f,r is the control character. The meaning of the book is to describe how the sender of the data stream wants the information to be formatted or represented.
Unicode escape characters are very interesting
it can be written anywhere in the code, as long as the escape is legal.
For example:
int c=0\u003b
The above code can be compiled through, equivalent to int c=0; \u003b is the '; ' The Unicode code
The above example is not convincing, so I wrote the following code to convert a string to a Unicode character
then you can put the printed code in the Egghello.java and run it, and the result is exciting.
/*
* Author: Egg DATE:2004/11/10 string converted to Unicode
*/
public class Asc2unicode {
private StringBuffer ch;
private StringBuffer tch;
Asc2unicode (StringBuffer s) {
ch = s;
if (ch.length () > 0)
tch = new StringBuffer (1000);
}
void transform () {
if (Ch.length () < 1)
return;
for (int i = 0; i < ch.length (); i++) {
((int) ch.charat (0)). toString ();
Tch.append (New StringBuffer ("\\u00"));
Tch.append (New StringBuffer (integer.tohexstring (int) ch
. CharAt (i))));
}
}
StringBuffer getstr () {
return tch;
}
public static void Main (string[] argv) {
asc2unicode au = new Asc2unicode (new StringBuffer (New String (
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.