package wzs.arithmetics;
/**
* 分别统计出其中字符串中汉字,英文字母,数字,其他字符数量
* @author wWX154783
*
*/
public class Test_wzs7
{
public static void main(String[] args)
{
String str = "a12中国3@b&4语*言3c";
String E1 = "[\u4e00-\u9fa5]";// 中文
String E2 = "[a-zA-Z]";// 英文
String E3 = "[0-9]";// 数字
int chineseCount = 0;
int englishCount = 0;
int numberCount = 0;
String temp;
for (int i = 0; i < str.length(); i++)
{
temp = String.valueOf(str.charAt(i));
if (temp.matches(E1))
{
chineseCount++;
}
if (temp.matches(E2))
{
englishCount++;
}
if (temp.matches(E3))
{
numberCount++;
}
}
System.out.println("汉字数:" + chineseCount);
System.out.println("英文数:" + englishCount);
System.out.println("数字数:" + numberCount);
System.out.println("特殊字符:" + (str.length() - (chineseCount + englishCount + numberCount)));
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。