51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 3696|回复: 6
打印 上一主题 下一主题

在WR中去字符串左右空格

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2007-7-12 12:18:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
刚做了一个项目,正好里面碰到一个末尾带空格的字符串,但我想得到的是不带字符串的,怎么办呢?我先看了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对对象的支持不是很好,有好多要自己写一些函数,希望大家也能把自己的基函数贡献出来,共同进步!!!!!!!!!!!!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2007-7-12 15:07:44 | 只看该作者
学习了。。。。
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2007-7-13 10:05:30 | 只看该作者
跑了一下确实可行哦,不过这句  if(tempstring==" " ||tempstring=="        ")

我认为直接用 if(tempstring==" ") 做条件就可以了,不需要做一个或表达式
回复 支持 反对

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2007-7-13 12:55:45 | 只看该作者

回复 #3 kolecat 的帖子

tempstring=="        "其实不是空格,而是TAB键,你可以试下在字符串中加TAB键看能否删去。
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2007-7-13 13:20:26 | 只看该作者
汗,果然是,没有想到是tab键的制表位sdlkfj8
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2007-7-14 21:09:41 | 只看该作者
编码规范很严格,考虑的也很周到,希望能看到lz更多的帖子!sdlkfj3
回复 支持 反对

使用道具 举报

该用户从未签到

7#
 楼主| 发表于 2007-7-16 09:09:45 | 只看该作者
呵呵 本人也刚开始学习WR 希望能够和大家共同进步!
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-14 01:10 , Processed in 0.074190 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表