Java 区分文本中的中英文字符函数
public class EnCnTest
{
public static void main(String args[])
{
byte buf[] = args.getBytes();
boolean halfChinese = false;
for(int i=0;i
{
if(halfChinese)
{
byte ch[] = {buf,buf};
System.out.println("索引"+(i-1)+"位置为中文("+new String(ch)+")");
halfChinese = false;
continue;
}
if((buf & 0x80) == 0)
{
System.out.println("索引"+i+"位置是英文("+(char)buf+")");
}
else
{
halfChinese = true;
}
}
}
}
https://www.uoften.com/program/jsp/20180413/47534.html
页:
[1]