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

//全局文本替换
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, "");
}


 

 

posted @ 2011-12-27 16:03  Cat.1988  阅读(268)  评论(0编辑  收藏  举报