1、去掉字符串前后空格
String.prototype.ltrim = function () {
return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function () {
return this.replace(/\s+$/, "");
}
String.prototype.trim = function () {
return this.ltrim().rtrim();
}
2、判断字符串是否以一个指定的字符串结尾
String.prototype.endWith = function (oString) {
var reg = new RegExp(oString + "$");
return reg.test(this);
};