function KillSpace(x){
while((x.length>0) && (x.charAt(0)==' '))
{
x = x.substring(1,x.length);
}
for (i=0;i<x.length;i++)
{
if (x.charAt(i)==' ')
{
x = x.substring(0,i)
}
}
alert("i"+x+"i");
}
String.prototype.trim = function()
{
return this.replace(/(^/s+)|/s+$/g,"");
}
博客给出了两段代码,一段自定义函数KillSpace用于去除字符串前后空格,另一段通过原型链为字符串添加trim方法,利用正则表达式去除前后空格,均与信息技术中JavaScript字符串处理相关。
799

被折叠的 条评论
为什么被折叠?



