Java Unicode Create toUnicodeSymbols(String s)

Here you can find the source of toUnicodeSymbols(String s)

Description

Translate the specified string to UNICODE presented code string.

License

Open Source License

Parameter

Parameter Description
s the specified string

Return

UNICODE presented code string

Declaration

public static String toUnicodeSymbols(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w ww  .j a  v a  2  s  .co  m*/
     * Translate the specified string to UNICODE presented code string.
     * 
     * @param s
     *            the specified string
     * @return UNICODE presented code string
     */
    public static String toUnicodeSymbols(String s) {
        StringBuffer sb = new StringBuffer();
        char a[] = s.toCharArray();
        for (char c : a)
            if (c < 256)
                sb.append(c);
            else if (c < 4096)
                sb.append(String.format("\\u0%h", (int) c));//$NON-NLS-1$
            else
                sb.append(String.format("\\u%h", (int) c));//$NON-NLS-1$
        return sb.toString();
    }
}

Related

  1. toUnicodeString(char c)
  2. toUnicodeString(char[] chars)
  3. toUnicodeString(String baseString)
  4. toUnicodeString(String s)
  5. toUnicodeString(String str)
  6. toUnicodeValue(char c)
  7. toUnicodeValue(char c)