收藏本站

中英混排文字长度截取

中文字符长度截取。

private static void printByteLength(String s ,String ecodingName){
   System.out.print("字节数: ");
   try {
   System.out.println(s.getBytes(ecodingName).length);
} catch (UnsupportedEncodingException e) {
   e.printStackTrace();
}
}

//判定是否是中文字符
private static boolean isChineseChar(char c) throws UnsupportedEncodingException{
   return String.valueOf(c).getBytes("GBK")....

阅读全文>>