在String中有个去除空格的方法spilt(),在js中也经常要去除空格,本人从网上找了一些方法,如下:
1. 去除所有空格:
str = str.replace(/\s+/g,"");
去除两头空格:
str = str.replace(/^\s+|\s+$/g,"");
2. function LTrim(str)
{
for (var i=0; str.charAt(i)==" "; i++);
return str.substring(i,str.length);
}
function RTrim(str)
{
for (var i=str.length-1; str.charAt(i)==" "; i--);
return str.substring(0,i+1);
}
function Trim(str)
{
return LTrim(RTrim(str));
}
附:sql中去除空格
str1="王二"
select * from cj where replcace(xm,' ','')='" & str1 & "'"
str1=left(str1,1) & "[ - ]" & right(str1,1)
select * from cj where xm='" & str1 & "'"
select * from cj where replcace(xm,' ','')='" & str1 & "'"
select replace(xm,' ','') as UserName from cj where replace(xm,' ','')='" & str1 & "'"
这是处理两个字中间有一个空格的方法,其他的类推。。