/**
* 字符转码
* @param theString
* @return
*/
public static String decodeUnicode(String theString){
char aChar;
int len = theString.length();
StringBuffer buffer = new StringBuffer(len);
for (int i = 0; i < len;) {
aChar = theString.charAt(i++);
if(aChar == '\\'){
aChar = theString.charAt(i++);
if(aChar == 'u'){
int val = 0;
for(int j = 0; j < 4; j++){
aChar = theString.charAt(i++);
switch (aChar) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
val = (val << 4) + aChar - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
val = (val << 4) + 10 + aChar - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
val = (val << 4) + 10 + aChar - 'A';
break;
default:
throw new IllegalArgumentException(
"Malformed encoding.");
}
}
buffer.append((char) val);
}else{
if(aChar == 't'){
aChar = '\t';
}
if(aChar == 'r'){
aChar = '\r';
}
if(aChar == 'n'){
aChar = '\n';
}
if(aChar == 'f'){
aChar = '\f';
}
buffer.append(aChar);
}
}else{
buffer.append(aChar);
}
}
return buffer.toString();
}
* 字符转码
* @param theString
* @return
*/
public static String decodeUnicode(String theString){
char aChar;
int len = theString.length();
StringBuffer buffer = new StringBuffer(len);
for (int i = 0; i < len;) {
aChar = theString.charAt(i++);
if(aChar == '\\'){
aChar = theString.charAt(i++);
if(aChar == 'u'){
int val = 0;
for(int j = 0; j < 4; j++){
aChar = theString.charAt(i++);
switch (aChar) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
val = (val << 4) + aChar - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
val = (val << 4) + 10 + aChar - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
val = (val << 4) + 10 + aChar - 'A';
break;
default:
throw new IllegalArgumentException(
"Malformed encoding.");
}
}
buffer.append((char) val);
}else{
if(aChar == 't'){
aChar = '\t';
}
if(aChar == 'r'){
aChar = '\r';
}
if(aChar == 'n'){
aChar = '\n';
}
if(aChar == 'f'){
aChar = '\f';
}
buffer.append(aChar);
}
}else{
buffer.append(aChar);
}
}
return buffer.toString();
}