|
马上加入TC
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
- namespace myStr
- //strRemove功能为:
- //若在str1包含str2这个字符,则从str1中移除str2,并返回str1。
- //若str1中包含多个str2,则从str1中移除第一个str2,并返回str1。
- //若str1中不包含str2,则返回str1
- function string strRemove(string str1,string str2)
- int tempStr1Len = str.strleng(str1)
- //help.messagebox( str.strcat("tempStr1Len=", convert.inttostr(tempStr1Len) ) )
- int tempStr2Len = str.strleng(str2)
- //help.messagebox( str.strcat("tempStr2Len=", convert.inttostr(tempStr2Len) ) )
- int tempIndex = str.findstr(str1,str2)
- //help.messagebox( str.strcat("tempIndex=", convert.inttostr(tempIndex) ) )
- if(tempIndex == -1)
- return str1
- endif
- if (tempIndex == 0)
- //help.messagebox( str.strcat("头str1=", str1) )
- return str.strcut(str1,tempStr2Len,true)
- else
- if(tempIndex == tempStr1Len - tempStr2Len)
- //help.messagebox( str.strcat("尾str1=", str1) )
- return str.strcut(str1,tempStr2Len,false)
- else
- string tempSub = str.strsub(str1,0,tempIndex)
- //help.messagebox( str.strcat("中str1=", str1) )
- return str.strcat(tempSub, str.strsub(str1,tempIndex+tempStr2Len,tempStr1Len) )
- endif
- endif
- endfunction
- endnamespace
复制代码
如题,经常会用到这么一个函数,从一个字符串中移除另外一个字符串,TC库中没有找到这个函数,我便写了个,强烈建议TC库能加入这类功能的函数~
有需要的人可以拿去用,经我初步测试,没错~
请需要的各位童鞋自行测试后使用~~ |
|