您的位置:首页 > Web前端 > JavaScript

javascript 字符串常用操作(replaceAll,trim)

2011-12-27 16:03 459 查看
//全局文本替换
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
}
//去前后空格
String.prototype.Trim = function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
}
//去前空格
String.prototype.LTrim = function(){
return this.replace(/(^\s*)/g, "");
}
//去后空格
String.prototype.RTrim = function(){
return this.replace(/(\s*$)/g, "");
}
//去除字符串中所有空格
String.prototype.trimStr = function(){
return this.replace(/\s+/g, "");
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript function