TC官方合作论坛

 找回密码
 立即注册
查看: 2031|回复: 6

[学习心得] 自己写的一个函数strRemove,强烈要求TC能加入这个函数,实用~~

[复制链接]
发表于 2011-12-12 11:10:48 | 显示全部楼层 |阅读模式

马上加入TC

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
  1. namespace myStr
  2. //strRemove功能为:
  3. //若在str1包含str2这个字符,则从str1中移除str2,并返回str1。
  4. //若str1中包含多个str2,则从str1中移除第一个str2,并返回str1。
  5. //若str1中不包含str2,则返回str1
  6. function string strRemove(string str1,string str2)
  7. int tempStr1Len = str.strleng(str1)
  8. //help.messagebox( str.strcat("tempStr1Len=", convert.inttostr(tempStr1Len) ) )
  9. int tempStr2Len = str.strleng(str2)
  10. //help.messagebox( str.strcat("tempStr2Len=", convert.inttostr(tempStr2Len) ) )
  11. int tempIndex = str.findstr(str1,str2)
  12. //help.messagebox( str.strcat("tempIndex=", convert.inttostr(tempIndex) ) )
  13. if(tempIndex == -1)
  14.     return str1
  15. endif
  16. if (tempIndex == 0)
  17.         //help.messagebox( str.strcat("头str1=", str1) )
  18.         return str.strcut(str1,tempStr2Len,true)
  19. else
  20.     if(tempIndex == tempStr1Len - tempStr2Len)
  21.         //help.messagebox( str.strcat("尾str1=", str1) )
  22.          return str.strcut(str1,tempStr2Len,false)
  23.     else
  24.         string tempSub = str.strsub(str1,0,tempIndex)
  25.         //help.messagebox( str.strcat("中str1=", str1) )
  26.         return str.strcat(tempSub, str.strsub(str1,tempIndex+tempStr2Len,tempStr1Len) )
  27.     endif
  28. endif
  29. endfunction
  30. endnamespace
复制代码

如题,经常会用到这么一个函数,从一个字符串中移除另外一个字符串,TC库中没有找到这个函数,我便写了个,强烈建议TC库能加入这类功能的函数~
有需要的人可以拿去用,经我初步测试,没错~
请需要的各位童鞋自行测试后使用~~
回复

使用道具 举报

发表于 2011-12-12 11:18:19 | 显示全部楼层
感觉楼主的支持,感谢楼主的分享。 好的东西我们都会吸收
回复 支持 反对

使用道具 举报

 楼主| 发表于 2011-12-12 11:33:55 | 显示全部楼层
感觉楼主的支持,感谢楼主的分享。 好的东西我们都会吸收
小东 发表于 2011-12-12 11:18:19
谢谢你的肯定,其实还有另外几个函数,我一会写了也都放出来~
然后还有一个小建议,我吃完饭后写完了也说说,呵呵~
回复 支持 反对

使用道具 举报

发表于 2011-12-12 12:44:24 | 显示全部楼层
:-|英文看不懂
回复 支持 反对

使用道具 举报

 楼主| 发表于 2011-12-12 13:05:54 | 显示全部楼层
:-|英文看不懂
JIANG_123 发表于 2011-12-12 12:44:24

呵呵,没办法,习惯英文的,期待有人出中文版的,其实自己写也行的,没什么难度。。
回复 支持 反对

使用道具 举报

发表于 2011-12-12 16:38:54 | 显示全部楼层
顶起,感谢分享,新人表示鸭梨很大
回复 支持 反对

使用道具 举报

发表于 2013-11-24 17:42:44 | 显示全部楼层
爱回帖爱积分,爱TC!!!!!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条

关闭

小黑屋|TC官方合作论坛 (苏ICP备18045623号)

GMT+8, 2024-5-17 17:22 , Processed in 0.041157 second(s), 24 queries .

Powered by 海安简单软件服务部

© 2008-2019 版权所有 保留所有权利

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