string Unicode - Java java.lang

Java examples for java.lang:String Unicode

Description

string Unicode

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String string = "java2s.com";
        System.out.println(string2Unicode(string));
    }//from ww w.j a va2 s .co m

    public static String string2Unicode(String string) {
        StringBuilder sb = new StringBuilder();
        int len = string.length();
        for (int i = 0; i < len; i++) {

            char c = string.charAt(i);

            sb.append("\\u" + Integer.toHexString(c));
        }
        return sb.toString();
    }
}

Related Tutorials