Differences between revisions 4 and 5
Revision 4 as of 2006-07-21 10:10:49
Size: 543
Editor: HoLin
Comment:
Revision 5 as of 2009-12-25 07:12:30
Size: 543
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

JavaScript

  • 双字节字符串处理
    •    1 String.prototype.leftB=function(len){
         2   var s=this.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**")
         3   return this.slice(0,s.slice(0,len).replace(/\*\*/g," ").replace(/\*/g,"").length)
         4 }
         5 String.prototype.lenB=function(){
         6   return this.replace(/\*/g," ").replace(/[^\x00-\xff]/g,"**").length
         7 }
         8 str="hi,我是中国人"
         9 alert("原始字符串:"+str+"\n字符串长度:"+str.length+"\n双字节长度:"+str.lenB()+"\n前10位字节:"+str.leftB(10))
      

HoLin/JavaScript (last edited 2009-12-25 07:12:30 by localhost)