Java Unicode Create toUnicodeString(String baseString)

Here you can find the source of toUnicodeString(String baseString)

Description

to Unicode String

License

LGPL

Declaration

public static String toUnicodeString(String baseString) 

Method Source Code

//package com.java2s;
/**/*from w  w w .ja  v  a  2  s .  c  o m*/
* Converts a line of text into an array of lower case words using a
* BreakIterator.wordInstance().
* <p>
* 
* This method is under the Jive Open Source Software License and was written
* by Mark Imbriaco.
* 
* @param text
*          a String of text to convert into an array of words
* @return text broken up into an array of words.
*/

public class Main {

    public static String toUnicodeString(String baseString) {
        return toUnicodeString(baseString, "\\u");
    }

    public static String toUnicodeString(String baseString, String prefix) {
        if (baseString == null)
            return null;
        else {
            char[] c = baseString.toCharArray();
            String ls_Return = "";
            for (int i = 0; i < c.length; i++) {
                int j = (int) c[i];
                if (j > 256) {
                    // j += Integer.parseInt("8000", 16);
                    ls_Return += prefix + right("0000" + Integer.toHexString(j), 4);
                } else {
                    ls_Return += prefix + right("00" + Integer.toHexString(j), 2);
                    // c[i];
                }
            }
            return ls_Return;
        }
    }

    public static String right(String baseString, int pos) {
        int diLength;
        int diSubString;
        if (baseString == null) {
            return null;
        } else {
            diLength = baseString.length();
            if (diLength < pos) {
                diSubString = 0;
            } else {
                diSubString = diLength - pos;
            }
            return baseString.substring(diSubString);
        }
    }

    public static final int length(String baseString) {
        if (baseString == null)
            return 0;
        else
            return baseString.length();
    }

    public static final String substring(String baseString, int start, int end) {
        if (baseString == null)
            return null;
        else if (start >= baseString.length() || start < 0 || end < 0 || start > end)
            return null;
        else if (end >= baseString.length())
            return baseString.substring(start);
        else {
            return baseString.substring(start, end);
        }
    }

    public static final String substring(String baseString, int start) {
        if (baseString == null)
            return null;
        else
            return substring(baseString, start, baseString.length());
    }
}

Related

  1. toUnicodeStr(int i)
  2. toUnicodeString(byte[] ba)
  3. toUnicodeString(byte[] data)
  4. toUnicodeString(char c)
  5. toUnicodeString(char[] chars)
  6. toUnicodeString(String s)
  7. toUnicodeString(String str)
  8. toUnicodeSymbols(String s)
  9. toUnicodeValue(char c)