Chinese To Unicode - Java java.lang

Java examples for java.lang:String Unicode

Description

Chinese To Unicode

Demo Code


//package com.java2s;

public class Main {
    public static String chinaToUnicode(String str) {
        String result = "";
        for (int i = 0; i < str.length(); i++) {
            int chr1 = (char) str.charAt(i);
            if (chr1 >= 19968 && chr1 <= 171941) {// \u4e00-\u9fa5
                result += "\\u" + Integer.toHexString(chr1);
            } else {
                result += str.charAt(i);
            }//from  ww w  .ja va  2 s .c  o m
        }
        return result;
    }
}

Related Tutorials