Java gets Char UFT-16 Code value

I tried several conversion methods, and the following conversion works:
String aaa = "À";
System.out.println(Integer.parseInt(Integer.toHexString(aaa.charAt(0)), 16));
System.out.println(Integer.parseInt(Integer.toHexString("љ".charAt(0)), 16));
System.out.println(Integer.parseInt(Integer.toHexString('₯'), 16));
 

In addition, if you need to print out each encoding format, you can refer to the following content (the following content is reproduced, thank the original author)

public static String getCode(String in) {
    String result = "";
    System.out.println(shang);
    try {
        result = URLEncoder.encode(in, "GBK");
        System.out.println("GBK:" + result);

        result = URLEncoder.encode(in, "UTF-8");
        System.out.println("UTF8: " + result);

        result = URLEncoder.encode(in, "UTF-16");
        System.out.println("UTF16:" + result);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return result;
}

 

Guess you like

Origin blog.csdn.net/cshoney/article/details/117334157