`
ycy303
  • 浏览: 191653 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

测字符串的长度(区分全角和半角)

 
阅读更多
//测字符串的长度,返回按照半角计算的长度
function CheckStringLength (txt) : Number
{
 var len : Number;
 len = 0;
 for (var i = 0; i < txt.length; i ++)
 {
  //trace(txt.charCodeAt(i))
  if (txt.charCodeAt (i) >= 0x4e00 && txt.charCodeAt (i) <= 0x9fa5)
  {
   //trace (txt.charAt (i));
   len += 2;
  } else
  {
   len += 1;
  }
 }
 return len;
}

 

2006.11.28

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics