public class Test
{
public static void Main (string[] args)
{
String s = "Set export template in transit";
String TT = gbencoding (s);
}
public static string gbencoding (final string gbstring)
{
char[] utfbytes = Gbstring.tochararray ();
String unicodebytes = "";
for (int byteindex = 0; Byteindex < utfbytes.length; byteindex++)
{
String Hexb = integer.tohexstring (Utfbytes[byteindex]);
if (Hexb.length () <= 2)
{
Hexb = "XX" + Hexb;
}
Unicodebytes = unicodebytes + "\\u" + Hexb;
}
System.out.println ("Unicodebytes is:" + unicodebytes);
return unicodebytes;
}
public static string Decodeunicode (final 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, end);
}
Char letter = (char) integer.parseint (CHARSTR, 16); 16 binary parse-shaped string.
Buffer.append (new Character (letter). ToString ());
start = end;
}
return buffer.tostring ();
}
}
Unicode and Chinese translation in Java