pb的replace完善

pb的replace来用,pb的replace完善
正常来说,在一个项目里都会写个全局replace函数,如下

$PBExportHeader$gf_replace.srf
global type gf_replace from function_object
end type

forward prototypes
global function string gf_replace (ref string as_source, string as_old, string as_new)
end prototypes

global function string gf_replace (ref string as_source, string as_old, string as_new);//gf_replace
//功能:在一个字符串(ls_temp)中将一字符串(as_old)替换成另一个字符串(as_new)
//返回:被替换成功后的字符串

string ls_temp
long ll_pos=1

ls_temp = as_source
// Find the first occurrence of as_old.
ll_pos = Pos(ls_temp, as_old, ll_pos)
// Only enter the loop if you find as_old.
DO WHILE ll_pos > 0
  // Replace as_old with as_new.
  ls_temp = Replace(ls_temp, ll_pos, Lenw(as_old), as_new)
  // Find the next occurrence of as_old.
  ll_pos = Pos(ls_temp, as_old, ll_pos+Lenw(as_new))
LOOP

return ls_temp
//
end function

你可能感兴趣的:(PB)