码迷,mamicode.com
首页 > 其他好文 > 详细

02.of_replace函数

时间:2015-12-06 11:25:26      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

pb8
自己写的:
  1. //====================================================================
  2. // 事件: w_main.of_replace()
  3. //--------------------------------------------------------------------
  4. // 描述:示例:of_replace("12-3--456-78-9",‘-‘,‘=‘,2)
  5. //--------------------------------------------------------------------
  6. // 参数:
  7. // value string as_string 原字符串
  8. // value string as_old 被替换的字符串;可以是多个字符,可以是中文
  9. // value string as_new
  10. // value long al_count 替换的次数,小于等于0不限制;
  11. //--------------------------------------------------------------------
  12. // 返回: string
  13. //--------------------------------------------------------------------
  14. // 作者: qxx 日期: 2015年11月24日
  15. //--------------------------------------------------------------------
  16. // 调用位置:
  17. //--------------------------------------------------------------------
  18. // 修改历史:
  19. // -------------------
  20. //注意:as_string的长度可能会出问题:
  21. // string: Any ASCII character with variable length (0 to 2,147,483,647).
  22. //====================================================================
  23. string ls_string,ls_old,ls_new,ls_return
  24. long ll_count,ll_pos,ll_start,ll_len,ll_count_rep
  25. ls_string = as_string
  26. ls_new = as_new
  27. ls_old = as_old
  28. ll_count = al_count
  29. ll_len = len(ls_old)
  30. ls_return = ""
  31. ll_pos = 0
  32. if isnull(ls_string) or ls_string = ‘‘ then
  33. return ""
  34. end if
  35. do while true
  36. ll_pos = pos(ls_string,ls_old,1)
  37. if ll_pos > 0 then
  38. if ll_count > 0 then ll_count_rep += 1
  39. ls_return += mid(ls_string,1,ll_pos - 1)+ls_new
  40. ls_string = mid(ls_string,ll_pos+ll_len)
  41. else
  42. ls_return += ls_string
  43. exit
  44. end if
  45. if ll_count_rep>=ll_count and ll_count > 0 then
  46. ls_return += ls_string
  47. exit
  48. end if
  49. loop
  50. return ls_return














02.of_replace函数

标签:

原文地址:http://www.cnblogs.com/QIAOXINGXING001/p/5023101.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!