`

JavaScript 实现 StartWith endWith trim 方法

 
阅读更多
<script type="text/javascript">
String.prototype.endWith=function(s){
if(s==null||s==""||this.length==0||s.length>this.length)
return false;
if(this.substring(this.length-s.length)==s)
return true;
else
return false;
return true;
}
String.prototype.startWith=function(s){
if(s==null||s==""||this.length==0||s.length>this.length)
return false;
if(this.substr(0,s.length)==s)
return true;
else
return false;
return true;
}

 

 

String.prototype.trim= function(){
// 用正则表达式将前后空格
// 用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, "");
}


</script>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics