Here you can find the source of toUnicode(String text)
Parameter | Description |
---|---|
text | String |
public static String toUnicode(String text)
//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(); } }