51Testing软件测试论坛
标题:
如何去掉一个字符串的首尾空格,用哪个函数。
[打印本页]
作者:
wts
时间:
2006-7-29 09:28
标题:
如何去掉一个字符串的首尾空格,用哪个函数。
如何去掉一个字符串的首尾空格,用哪个函数。谢谢
作者:
winterson
时间:
2006-7-29 18:38
写了一个函数,已经实验成功了:
#############################################################
#作用:在SourceStr中过滤指定的字符;
#参数:
# SourceStr :原字符串;
#
#
# option:过滤左还是右,默认右;左:"L",右:"R"全部:"D"
#
# 返回值:新的字符串
##############################################################
public function Trim_Space( in SourceStr,in option)
{
auto slen,InvailLorRStr="LRD",testname,lineno,funcname;
if (nargs()==1 ) #一个参数时表示过滤右边空格
option="R";
if((length(option)!=1)||(index(InvailLorRStr,option)==0))
{
call_chain_get_attr("testname", 1, testname);
call_chain_get_attr("line_no", 1, lineno);
call_chain_get_attr("function",1,funcname);
pause(testname&"中的第"&lineno&"行"funcname&"函数第二个参数有误" );
return E_STR_ILLEGAL_PARAM;
}
slen = length( SourceStr );
switch(option)
{
case "R":
{
if ( substr( SourceStr, slen ) == " " )
SourceStr = Trim_Space( substr( SourceStr, 1, slen-1),"R");
break;
}
case "L":
{
if (substr(SourceStr,1,1)==" ")
SourceStr=Trim_Space(substr(SourceStr,2,slen),"L");
break;
}
case "D":
{
SourceStr = Trim_Space( substr( SourceStr, 1, slen-1),"R");
SourceStr=Trim_Space(substr(SourceStr,2,slen),"L");
break;
}
}
return SourceStr;
}
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2