快捷搜索:

一个JavaScript字符串处理函数

//截取字符串 包孕中文处置惩罚

function SubString(str, len, hasDot) {

var newLength = 0;

var newStr = "";

var chineseRegex = /[^\x00-\xff]/g;

var singleChar = "";

var strLength = str.replace(chineseRegex, "**").length;

for (var i = 0; ilen) {

break;

}

newStr += singleChar;

}

if (hasDot && strLength > len) {

newStr += "...";

}

return newStr;

}

//字符串连接

function StringBuffer() {

this._string = new Array;

}

StringBuffer.prototype.append = function(str) {

return this._string.push(str);

}

StringBuffer.prototype.toString = function() {

return this._string.join("");

}

您可能还会对下面的文章感兴趣: