Privatestring Decodeunicode (String thestring) {CharAchar; intLen =thestring.length (); StringBuffer Outbuffer=NewStringBuffer (len); for(intx = 0; X <Len;) {Achar= Thestring.charat (x + +); if(Achar = = ' \ \ ') {Achar= Thestring.charat (x + +); if(Achar = = ' U ') { //Read the XXXX intValue = 0; for(inti = 0; I < 4; i++) {Achar= Thestring.charat (x + +); Switch(Achar) { Case' 0 ': Case' 1 ': Case' 2 ': Case' 3 ': Case' 4 ': Case' 5 ': Case' 6 ': Case' 7 ': Case' 8 ': Case' 9 ': Value= (value << 4) + Achar-' 0 '; Break; CaseA: Case' B ': CaseC: Case' d ': CaseE: Case' F ': Value= (value << 4) + + Achar-' a '; Break; CaseA: CaseB: CaseC: CaseD: CaseE: CaseF: Value= (value << 4) + + Achar-' A '; Break; default: Throw NewIllegalArgumentException ("Malformed \\UXXXX encoding."); }} outbuffer.append ((Char) value); } Else { if(Achar = = ' t ') Achar= ' \ t '; Else if(Achar = = ' R ') Achar= ' \ r '; Else if(Achar = = ' n ') Achar= ' \ n '; Else if(Achar = = ' F ') Achar= ' \f '; Outbuffer.append (Achar); } } Elseoutbuffer.append (Achar); } returnoutbuffer.tostring (); }
Java encoding convert Unicode to Utf-8