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