Re: Standard toolkit
- Posted by "Kat" <gertie at visionsix.com> Jul 07, 2005
- 577 views
Someone mentioned replace() earlier, here is the one i use, it's case- insensitive, with a wildcard matching:
function replace(sequence st,sequence old_ch,sequence new_ch) integer k, k1, k2 sequence newst, old_ch1, old_ch2 if match("*",old_ch) then old_ch1 = old_ch[1..match("*",old_ch)-1] old_ch2 = old_ch[match("*",old_ch)+1..length(old_ch)] k1 = match(upper(old_ch1),upper(st)) k2 = match(upper(old_ch2),upper(st)) newst = "" while (k1 and k2) and (k2 > k1) do newst = newst & st[1..k1-1] & new_ch st = st[k1..length(st)] st = st[k2 + length(old_ch2)..length(st)] k1 = match(upper(old_ch1),upper(st)) k2 = match(upper(old_ch2),upper(st)) end while newst = newst & st return newst else k = match(upper(old_ch),upper(st)) newst = "" while k do newst = newst & st[1..k-1] & new_ch st = st[k+length(old_ch)..length(st)] k = match(upper(old_ch),upper(st)) end while newst = newst & st return newst end if end function
works like: TheWebPage = replace(TheWebPage,")","\"") TheWebPage = replace(TheWebPage,"<font*>","") It can be sped up some, i'm sure. My 2nd version of replace is a bit ratty, but has a case switch, a do_not_replace switch, and a do_replace_only switch. Maybe i'll post it when cleaned up. Kat