怎样讲string转换成unicode,请高手来?

解决方案 »

  1.   

    byte [] b=s.getBytes("unicode");//转换到byte数组
    new String(b,"unicode")//数组转换到字符
      

  2.   

    import java.io.UnsupportedEncodingException;public class String2Unicode { /**
     * @param args
     * @throws UnsupportedEncodingException
     */
    public static void main(String[] args) throws UnsupportedEncodingException {
    String code = "unicode";
    String strText = "王胡子";
    char c;
    String strRet = "";
    int intAsc;
    String strHex;
    System.out.println(strText);
    for (int i = 0; i < strText.length(); i++) {
    c = strText.charAt(i);
    intAsc = (int) c;
    if (intAsc > 128) {
    strHex = Integer.toHexString(intAsc);
    strRet = strRet + " " + strHex;
    } else {
    strRet = strRet + c;
    }
    }
    System.out.println("unicode:"+strRet);
    }}
      

  3.   

    java中字符串本来就是Unicode编码的,不用转换。如果要把含中文的文本内容转成Unicode编码值显示,可以用JDK自带的native2ascii命令。在JDK的bin目录下运行native2ascii.exe,输入中文文本回车就可以了。
      

  4.   

    什么叫做把 String 转为 Unicode ?