姿姿霸霸~~!
贵在坚持!
posts - 106,  comments - 50,  trackbacks - 0
1.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, "");
}

2.全文匹配替换
var regExp = new RegExp("需要被替换的字符',"g")
var text = "…………";
text = text.replace(regExp , "替换的字符");

3.方案
String .prototype.trim = function(){
   var matches = this.match(/^[ \t\n\r]+/);
   var prefixLength = (matches == null) ? 0:matches[0].length;
   matches = this.match(/[ \t\r\n]+$/);
   var suffixLength = (matches == null) ? 0:matches[0].length;
   return this.slice(prefixLength,this.length-suffixLength);
}
posted on 2008-08-27 16:12 xrzp 阅读(8960) 评论(2)  编辑  收藏 所属分类: js

FeedBack:
# re: 去除空格的js 和 使用正则表达式替换[未登录]
2010-08-18 10:46 | 123
123 123 123 123 123 123  回复  更多评论
  
# re: 去除空格的js 和 使用正则表达式替换
2013-08-28 15:13 | fff fddd
dfasfdsa  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航:
 

<2008年8月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(4)

随笔分类

随笔档案

好友的blog

搜索

  •  

积分与排名

  • 积分 - 115052
  • 排名 - 505

最新评论

阅读排行榜

评论排行榜