javascript:去除字符串的前后空格
2008-06-08 20:54
288 查看
By Ben
方法一:
function KillSpace(x){
while((x.length>0) && (x.charAt(0)==' '))
x = x.substring(1,x.length);
//while((x.length>0) && (x.charAt(x.length-1)==' '))
while(x.length>0)
x = x.substring(0,x.length-1);
alert("Kill=" + x + "==")
return x;
}
实例: var a = KillSpace(“ abc “); //得出a == “abc“
方法二:
String.prototype.trim = function()
{
return this.replace(/(^/s+)|/s+$/g,"");
}
实例: var a = “ abc “.trim(); //得出a == “abc“
方法一:
function KillSpace(x){
while((x.length>0) && (x.charAt(0)==' '))
x = x.substring(1,x.length);
//while((x.length>0) && (x.charAt(x.length-1)==' '))
while(x.length>0)
x = x.substring(0,x.length-1);
alert("Kill=" + x + "==")
return x;
}
实例: var a = KillSpace(“ abc “); //得出a == “abc“
方法二:
String.prototype.trim = function()
{
return this.replace(/(^/s+)|/s+$/g,"");
}
实例: var a = “ abc “.trim(); //得出a == “abc“
相关文章推荐
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- JavaScript去除字符串前后的空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript 去除字符串中所有的空格or前后的双引号
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- javascript:去除字符串的前后空格
- JavaScript中如何去除字符串前后的空格?
- 用javascript写一个函数,作用是去除字符串前后空格