搜索文章:

首页  |  Java技术  |  Asp.net  |  Asp编程  |  VC/C++  |  Delphi  |  VB编程

正则表达式Replace

作者: unknow
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 + ")");

下一篇:正则表达式 >>
相关文章:
© 2006   www.java-asp.net