lantianwei 2007-7-12 12:18
在WR中去字符串左右空格
刚做了一个项目,正好里面碰到一个末尾带空格的字符串,但我想得到的是不带字符串的,怎么办呢?我先看了WR,看他是否自带了这样的函数,但结果另我非常失望。那咋办呢?还是自己写吧!以下就是本人写的TSL脚本,希望能和大家共享,不足之处还请大家指正!
##############################################################################################################
#
# Description---------This function is used to Delete the Right space
#
# Parameter---------inString(which string you want to delete right space)
#
# Return Value------outstring(which string by deleting the right space)
#
##############################################################################################################
public function D_RightTrim(inString)
{
auto i,len,outstring,tempstring,j;
len=length(inString);
for(i=len;;i--)
{
tempstring=substr(inString,i,1);
if(tempstring==" " ||tempstring==" ")
{
j=i;
}
else
{
break;
}
}
outstring=substr(inString,1,j-1);
return outstring;
}
##############################################################################################################
#
# Description---------This function is used to Delete the Left space
#
# Parameter---------inString(which string you want to delete Left space)
#
# Return Value------outstring(which string by deleting the Left space)
#
##############################################################################################################
public function D_LeftTrim(inString)
{
auto i,j,len,outstring,tempstring;
len=length(inString);
for(i=1;;i++)
{
tempstring=substr(inString,i,1);
if(tempstring==" " ||tempstring==" ")
{
j=i;
}
else
{
break;
}
}
outstring=substr(inString,j+1,len-j);
return outstring;
}
##############################################################################################################
#
# Description---------This function is used to Delete the Right space and the Left space
#
# Parameter---------inString(which string you want to delete right space and Left space)
#
# Return Value------outstring(which string by deleting the right space anfd the Left space)
#
##############################################################################################################
public function D_RLTrim(inString)
{
return D_LeftTrim(D_RightTrim(inString));
}
WR对对象的支持不是很好,有好多要自己写一些函数,希望大家也能把自己的基函数贡献出来,共同进步!!!!!!!!!!!!
snoopyzxbc 2007-7-12 15:07
学习了。。。。
kolecat 2007-7-13 10:05
跑了一下确实可行哦,不过这句 if(tempstring==" " ||tempstring==" ")
我认为直接用 if(tempstring==" ") 做条件就可以了,不需要做一个或表达式
lantianwei 2007-7-13 12:55
回复 #3 kolecat 的帖子
tempstring==" "其实不是空格,而是TAB键,你可以试下在字符串中加TAB键看能否删去。
kolecat 2007-7-13 13:20
汗,果然是,没有想到是tab键的制表位sdlkfj8
dionysus 2007-7-14 21:09
编码规范很严格,考虑的也很周到,希望能看到lz更多的帖子!sdlkfj3
lantianwei 2007-7-16 09:09
呵呵 本人也刚开始学习WR 希望能够和大家共同进步!