Restored from previous forum. Originally posted by wayne1.
;Extended Replace text procedure
;source = string to search
;find = string to find
;replace = text to replace find
;begin = which character to start at
;times = number of times to repeat replacement
initrequester()
s$="Testing Testing Testing"
Procedure.s ReplaceEx(source.s,find.s,replace.s,begin.w,times.w)
start.w=1
stop.w=0
replaceLen=len(replace)
source=right(source,len(source) - begin + 1)
While start0
start=FindString(source,find,start);
If start > 0
source = left(source,start-1) + replace + mid(source,start + len(find),len(source))
start = start + replaceLen
stop = stop + 1
If stop = times
start=0
EndIf
EndIf
Wend
ProcedureReturn source
EndProcedure
a$=ReplaceEx(s$,"ing","ed",1,2)
messagerequester("",a$+chr(13)+"Started at first character replaced two ocurrences of ing." ,0)
Edited by - wayne1 on 15 July 2001 03:10:00