杨的空间
业精于勤,荒于嬉,行成于思,毁于随
摘自csdn

即认为中文长度为2

方法一

byte[] mybyte=System.Text.Encoding.Default.GetBytes(str);

mybyte.Length

方法二

 public double CnLen(string str)
 {
  ASCIIEncoding n=new ASCIIEncoding();
  byte [] mybyte=n.GetBytes(str);
  double len=str.Length;
  for(int i=0;i<str.Length;i++)
  {
  if(mybyte[i]==63)
  {
   len=len+1;
  }
  }
  return len/2;

//  int temp;
//  double len=str.Length;
//  for(int i=0;i<str.Length;i++) 
//  {
//  temp=(int)str[i];
//  if(temp<0)
//  {
//   temp+=65536;
//  }
//  if(temp>255)
//  {
//   len+=1;
//  }
//  }
//  return len/2;
 }
posted on 2006-02-20 08:47 阅读(1788) 评论(0)  编辑 收藏 引用 所属分类: 技术类
只有注册用户登录后才能发表评论。