Java Unicode unicodeEncode(String s)

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

Description

unicode encoding (for verbose mode)

License

Apache License

Declaration

public static String unicodeEncode(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  w ww.j  a v  a  2  s  .c  o  m*/
     * unicode encoding (for verbose mode)
     */
    public static String unicodeEncode(String s) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < s.length(); ++i) {
            char ch = s.charAt(i);
            if (ch >= '\u0080') {
                String st = Integer.toHexString(0x10000 + (int) ch);
                while (st.length() < 4)
                    st = "0" + st;
                buf.append("\\u").append(st.subSequence(1, 5));
            } else {
                buf.append(ch);
            }
        }
        return buf.toString();
    }
}

Related

  1. unicode2native(String s)
  2. unicodeChar(char a, char b, char c, char d)
  3. unicodeCodepointToString(char cp, boolean shortenIfPossible, String prefix, boolean upperCase)
  4. unicodeConvert(String str)
  5. unicodeCount(String sStr)
  6. unicodeHTMLEscape(final String s)
  7. unicodePreservingIndex(String str, int index)
  8. unicodePreservingSubstring(String str, int begin, int end)
  9. unicodeToChar(char[] unicode)