package com.youku.paycenter.admin.subGate.service.impl;
import java.io.UnsupportedEncodingException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TestString
{
public static final String CHINESE_REG_EXP = "[\u4e00-\u9fa5]";
public static void main(String[] args) throws UnsupportedEncodingException
{
String s = "故人西辞黄鹤楼,烟花三月下扬州;孤帆远影碧空尽,唯见长江天际流。故人西辞黄鹤楼,烟花三月下扬州;孤帆远影碧空尽,唯见长江天际流。故人西辞黄鹤楼,烟花三月下扬州;孤帆远影碧空尽,唯见长江天际流。故人西辞黄鹤楼,烟花三月下扬州;孤帆远影碧空尽,唯见长江天际流。故人西辞黄鹤楼,烟花三月下扬州;孤帆远影碧空尽,唯见长江天际流。故人西辞黄鹤楼,烟花三月下扬州;孤帆远影碧空尽,唯见长江天际流。故人西辞黄鹤楼,abc";
if(isChineseChar(s))
{
char[] c_array = s.toCharArray();
String c_string = null;
byte[] c_byte_array;
int chineseCount = 0;
int normalCount = 0;
for (char c : c_array)
{
c_string = Character.toString(c);
c_byte_array = c_string.getBytes("UTF-8");
if(c_byte_array.length>1)
{
chineseCount++;
}
else
{
normalCount++;
}
}
System.out.println(chineseCount+normalCount);
}
}
public static boolean isChineseChar(String str)
{
if (str == null) return false;
boolean temp = false;
Pattern p = Pattern.compile(CHINESE_REG_EXP);
Matcher m = p.matcher(str);
if (m.find())
{
temp = true;
}
return temp;
}
}