TC官方合作论坛
标题:
自己写的一个函数strRemove,强烈要求TC能加入这个函数,实用~~
[打印本页]
作者:
我就喜欢呵呵呵
时间:
2011-12-12 11:10
标题:
自己写的一个函数strRemove,强烈要求TC能加入这个函数,实用~~
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库能加入这类功能的函数~
有需要的人可以拿去用,经我初步测试,没错~
请需要的各位童鞋自行测试后使用~~
作者:
TC管理员
时间:
2011-12-12 11:18
感觉楼主的支持,感谢楼主的分享。 好的东西我们都会吸收
作者:
我就喜欢呵呵呵
时间:
2011-12-12 11:33
感觉楼主的支持,感谢楼主的分享。 好的东西我们都会吸收
小东 发表于 2011-12-12 11:18:19
谢谢你的肯定,其实还有另外几个函数,我一会写了也都放出来~
然后还有一个小建议,我吃完饭后写完了也说说,呵呵~
作者:
JIANG_123
时间:
2011-12-12 12:44
:-|英文看不懂
作者:
我就喜欢呵呵呵
时间:
2011-12-12 13:05
:-|英文看不懂
JIANG_123 发表于 2011-12-12 12:44:24
呵呵,没办法,习惯英文的,期待有人出中文版的,其实自己写也行的,没什么难度。。
作者:
ltsi001
时间:
2011-12-12 16:38
顶起,感谢分享,新人表示鸭梨很大
作者:
yangfusheng
时间:
2013-11-24 17:42
爱回帖爱积分,爱TC!!!!!!
欢迎光临 TC官方合作论坛 (http://bbs.52tc.co/)
Powered by Discuz! X3.1