1、清除左空格/右空格
function ltrim(s){ return s.replace( /^(/s*| *)/, ""); } function rtrim(s){ return s.replace( /(/s*| *)$/, ""); }
2、判断是否以某个字符串开头
String.prototype.startWith = function (s) { return this.indexOf(s) == 0 }
3、判断是否以某个字符串结束
String.prototype.endWith = function (s) { var d = this.length - s.length; return (d >= 0 && this.lastIndexOf(s) == d) }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8851.html