Wie unten gezeigt:
Paket test.com.gjob.services; Import Java.util.Properties; public class test {public static void main (String [] args) {String S = "Einführung"; String tt = gbencoding (s); // String tt1 = "Hallo, ich möchte dir etwas sagen"; System.out.println (decodeUnicode ("// u7b80 // u4ecb")); // system.out.println (decodeunicode (tt1)); System.out.println (htmdecoder.decode ("China")); String s1 = "/u7b80/u4ecb"; System.out.println (S.Indexof ("//")); } public static String gbencoding (endgültige Zeichenfolge gbstring) {char [] utfBytes = gbstring.toCharArray (); String unicodeBytes = ""; für (int byteIndex = 0; byteIndex <utfBytes.length; byteIndex ++) {String hexb = Integer if (hexb.length () <= 2) {hexb = "00" + hexb; } unicodeBytes = unicodeBytes + "// u" + hexb; } System.out.println ("unicodeBytes ist:" + unicodeBytes); return unicodeBytes; } public static String decodeUnicode (endgültiger String -DataStr) {int start = 0; int End = 0; Final StringBuffer Buffer = new StringBuffer (); while (start> -1) {end = datastr.indexof ("// u", start + 2); String charstr = ""; if (end == -1) {charstr = datastr.substring (start + 2, datastr.length ()); } else {charstr = datastr.substring (Start + 2, Ende); } char Letter = (char) Integer.ParseInt (Charstr, 16); // Hexadezimal analysieren Plastikformungsschnur. buffer.Append (neuer Zeichen (Buchstaben) .ToString ()); Start = Ende; } return buffer.toString (); }} public static String decodeUnicode (String thestring) {char achar; int len = thestring.length (); StringBuffer Outbuffer = new StringBuffer (len); für (int x = 0; x <len;) {Achar = thestring.charat (x ++); if (Achar == '//') {Achar = thestring.charat (x ++); if (Achar == 'u') {// Lesen Sie den xxxx int value = 0; für (int i = 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'; brechen; Fall 'a': case 'b': case 'c': case 'd': case 'e': case 'f': value = (value << 4) + 10 + achar - 'a'; brechen; Fall 'a': case 'b': case 'c': case 'd': case 'e': case 'f': value = (value << 4) + 10 + achar - 'a'; brechen; Standard: Wirf eine neue IllegalArgumentException ("Fehlformiert // uxxxx codieren"); }} outbuffer.Append ((char) Wert); } else {if (Achar == 't') Achar = '/t'; sonst wenn (Achar == 'r') Achar = '/r'; sonst wenn (Achar == 'n') Achar = '/n'; sonst wenn (Achar == 'n') Achar = '/n'; sonst wenn (Achar == 'f') Achar = '/f'; Outbuffer.Append (Achar); }} else Outbuffer.Append (Achar); } return outbuffer.toString (); }Die einfache Implementierung der Umwandlung von Unicode und Chinesen in Java im obigen Artikel ist der gesamte Inhalt, den ich mit Ihnen teile. Ich hoffe, Sie können Ihnen eine Referenz geben und ich hoffe, Sie können wulin.com mehr unterstützen.