标题:
用脚本(JavaScript)去掉字符串的前后空格
[打印本页]
作者:
fangzhen
时间:
2009-2-16 10:38
标题:
用脚本(JavaScript)去掉字符串的前后空格
function Trim(str)
{
var i = 0;
var len = str.length;
if ( str == "" ) return( str );
j = len -1;
flagbegin = true;
flagend = true;
while ( flagbegin == true && i< len)
{
if ( str.charAt(i) == " " )
{
i=i+1;
flagbegin=true;
}
else
{
flagbegin=false;
}
}
while (flagend== true && j>=0)
{
if (str.charAt(j)==" ")
{
j=j-1;
flagend=true;
}
else
{
flagend=false;
}
}
if ( i > j ) return ("")
trimstr = str.substring(i,j+1);
return trimstr;
}
欢迎光临 PHP开发笔记 (http://phpvi.com/)
Powered by Discuz! 6.1.0