十进制形式的Unicode编码和字符转换,例如 36215<->北 (&#36215;)

  /**
  * 将十进制形式的Unicode编码转换为字符,例如   36215->北 (&#36215;)
  * @param codePoints
  * @return
  */
 public static String fromCharCode(int... codePoints) {
  
  StringBuilder builder = new StringBuilder(codePoints.length); 
  for (int codePoint : codePoints){      
   builder.append(Character.toChars(codePoint));  
   }   
         return builder.toString();
   }
 
 /**
  * 将&#36215;&#39134; 转化为 只含有整数值的数组   result[0]=36215,result[1]=39134
  * @param unicodeStr
  * @return
  */
 public static int[] removeUnicodeFlag(String unicodeStr){
  String regex = "&#(\\d+);";
  int result[]  = new int[unicodeStr.split(";").length];
  Pattern p = Pattern.compile(regex);
  Matcher ma = p.matcher(unicodeStr);
  int i = 0;
  while (ma.find()) {
   result[i++] = Integer.parseInt(ma.group(1));
  }
  return result;
 }
 
posted @ 2011-09-04 13:36  0707  阅读(4689)  评论(0编辑  收藏  举报