String.prototype.len=function(){ return this.replace(/[^\x00-\xff]/g,"rr").length; } String.prototype.sub = function(n){ var r = /[^\x00-\xff]/g; if(this.replace(r, "mm").length <= n) return this; var m = n;//Math.floor(n/2); for(var i=m; i<this.length; i++) { if(this.substr(0, i).replace(r, "mm").length>=n) { return this.substr(0, i); } } return this; };
js string 截断中英文字串
最新推荐文章于 2022-08-20 14:56:41 发布