如何去掉一个字符串的首尾空格,用哪个函数。
如何去掉一个字符串的首尾空格,用哪个函数。谢谢 写了一个函数,已经实验成功了:#############################################################
#作用:在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;
}
页:
[1]