Java区分文本中的中英文字符程序

http://www.itjxue.com  2015-07-17 01:12  来源:未知  点击次数: 

  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("索引"+(i-1)+"位置为中文("+new String(ch)+")");

  halfChinese = false;

  continue;

  }

  if((buf[i] & 0x80) == 0)

  {

  System.out.println("索引"+i+"位置是英文("+(char)buf[i]+")");

  }

  else

  {

  halfChinese = true;

  }

  }

  }

  }

(责任编辑:IT教学网)

更多

推荐java认证文章