Convert string To Unicode - Android java.lang

Android examples for java.lang:String Unicode

Description

Convert string To Unicode

Demo Code


public class Main {

  public static String stringToUnicode(String strText) throws Exception {
    char c;/*from w ww  . j  a  va  2  s .  c  o  m*/
    String strRet = "";
    int intAsc;
    String strHex;
    for (int i = 0; i < strText.length(); i++) {
      c = strText.charAt(i);
      intAsc = (int) c;
      strHex = Integer.toHexString(intAsc);
      if (intAsc > 128) {
        strRet += "\\u" + strHex;
      } else {
        strRet += "\\u00" + strHex;
      }
    }
    return strRet;
  }

}

Related Tutorials