public String toUnicode(String info)
{
StringBuffer tmp = new StringBuffer() ;
for(char cc : info.toCharArray())
{
UnicodeBlock ub = Character.UnicodeBlock.of(cc);
if(Arrays.asList(unicodeBlocks).contains(ub)){
tmp.append(cc);
} else{
String hexS = Integer.toHexString(cc);
if(hexS.length()==3){
hexS = "0" + hexS;
}else if(hexS.length()==2){
hexS = "00" + hexS;
}
String unicode = "\\u"+hexS;
tmp.append(unicode);
}
}
String infos = tmp.toString();
return infos;
}
private static final UnicodeBlock[] unicodeBlocks = new UnicodeBlock[]{
UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS,
UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION,
UnicodeBlock.CJK_COMPATIBILITY,
UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS,
UnicodeBlock.HANGUL_SYLLABLES,
UnicodeBlock.ARABIC,
UnicodeBlock.BASIC_LATIN,
UnicodeBlock.LATIN_1_SUPPLEMENT,
UnicodeBlock.LATIN_EXTENDED_A,
UnicodeBlock.LATIN_EXTENDED_B,
UnicodeBlock.KATAKANA,
UnicodeBlock.HIRAGANA,
UnicodeBlock.BOPOMOFO,
UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS,
UnicodeBlock.GEOMETRIC_SHAPES,
UnicodeBlock.GREEK,
UnicodeBlock.COMBINING_DIACRITICAL_MARKS,
UnicodeBlock.IPA_EXTENSIONS,
UnicodeBlock.LETTERLIKE_SYMBOLS,
UnicodeBlock.CURRENCY_SYMBOLS,
UnicodeBlock.MUSICAL_SYMBOLS,
UnicodeBlock.MISCELLANEOUS_SYMBOLS,
UnicodeBlock.TAI_XUAN_JING_SYMBOLS,
UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS,
UnicodeBlock.SUPPLEMENTAL_ARROWS_A,
UnicodeBlock.SUPPLEMENTAL_ARROWS_B,
UnicodeBlock.BRAILLE_PATTERNS,
UnicodeBlock.BLOCK_ELEMENTS,
UnicodeBlock.CONTROL_PICTURES,
UnicodeBlock.AEGEAN_NUMBERS,
UnicodeBlock.DINGBATS,
UnicodeBlock.LATIN_EXTENDED_ADDITIONAL,
UnicodeBlock.CYRILLIC,
UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS,
UnicodeBlock.GENERAL_PUNCTUATION
};