Java Unicode Create toUnicode(String text)

Here you can find the source of toUnicode(String text)

Description

Unicode????

License

LGPL

Parameter

Parameter Description
text String

Return

String

Declaration

public static String toUnicode(String text) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from www  .  j a  va  2s .  com
     * ????????Unicode????
     *
     * @param text
     *            String
     * @return String
     */
    public static String toUnicode(String text) {
        StringBuffer strBuffer = new StringBuffer();
        if (text == null) {
            return "";
        }
        char[] cArray = text.toCharArray();
        final int cArrayLength = cArray.length;
        strBuffer.delete(0, strBuffer.length());
        String hexStr;
        for (int i = 0; i < cArrayLength; i++) {
            strBuffer.append("\\u");
            hexStr = Integer.toHexString(cArray[i]);
            for (int j = 0; j < 4 - hexStr.length(); j++) {
                strBuffer.append('0');
            }
            strBuffer.append(hexStr);
        }
        return strBuffer.toString();
    }
}

Related

  1. toUnicode(String str)
  2. toUnicode(String str)
  3. toUnicode(String string)
  4. toUnicode(String strText)
  5. toUnicode(String text)
  6. toUnicode(String theString, boolean escapeSpace)
  7. toUnicode(String value)
  8. toUnicode(StringBuilder strBuilder, char ch)
  9. toUnicodeBytes(String str)