Replace Text Procedure

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wayne1.

;Replace text procedure
;source = string to search
;find = string to find
;replace = text to replace find

initrequester()

s$="Testing Testing"

Procedure.s Replace(source.s,find.s,replace.s)
start.w=1
replaceLen=len(replace)
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
EndIf
Wend
ProcedureReturn source

EndProcedure

a$=Replace(s$,"ing","ed")
messagerequester("",a$,0)