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 = "The Yellow crane Tower, the fireworks under the march of Yangzhou; lonely sail Far Shadow Azure sky, only see the Yangtze River days Inter flow. The Yellow Crane Tower, the words of the West, fireworks in the march of Yangzhou, Lone sail far shadow Azure, only see the Yangtze River Horizon flow. The Yellow Crane Tower, the words of the West, fireworks in the march of Yangzhou, Lone sail far shadow Azure, only see the Yangtze River Horizon flow. The Yellow Crane Tower, the words of the West, fireworks in the march of Yangzhou, Lone sail far shadow Azure, only see the Yangtze River Horizon flow. The Yellow Crane Tower, the words of the West, fireworks in the march of Yangzhou, Lone sail far shadow Azure, only see the Yangtze River Horizon flow. The Yellow Crane Tower, the words of the West, fireworks in the march of Yangzhou, Lone sail far shadow Azure, only see the Yangtze River Horizon flow.
The Yellow Crane Tower, abc "of the western words;
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 to temp;
}
}