当前位置:开发者网络 >> 技术教程 >> .NET教程 >> Asp.Net开发 >> 内容
精彩推荐
分类最新教程
分类热点教程
  
正则表达式Replace
作者:未知
日期:2004-12-01
人气:
投稿:snow(转贴)
来源:未知
字体:
收藏:加入浏览器收藏
以下正文:
String.prototype.trim= function()
{
// 用正则表达式将前后空格
// 用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, "");
}





// 有空格的字符串
var s = " leading and trailing spaces ";

// 显示 " leading and trailing spaces (35)"
window.alert(s + " (" + s.length + ")");

// 删除前后空格
s = s.trim();
// 显示"leading and trailing spaces (27)"
window.alert(s + " (" + s.length + ")");

相关文章: