Java distinguishes between Chinese and English character functions in text
- 2020-05-10 18:37:32
- OfStack
public class EnCnTest
{
public static void main(String args[])
{
byte buf[] = args[0].getBytes();
boolean halfChinese = false;
for(int i=0;i
{
if(halfChinese)
{
byte ch[] = {buf[i-1],buf[i]};
System.out.println(" The index "+(i-1)+" Location in Chinese ("+new String(ch)+")");
halfChinese = false;
continue;
}
if((buf[i] & 0x80) == 0)
{
System.out.println(" The index "+i+" The location is in English ("+(char)buf[i]+")");
}
else
{
halfChinese = true;
}
}
}
}