Login
`
Templates, Tools and Utilities
|
||
Icetips Article
Back to article list
Search Articles
Add Comment
Printer friendly
Direct link
Functions: Replace function 2004-06-04 -- Jonathan Kay Newsgroups: comp.lang.clarion
> I need a procedure something like this
> ReplaceString(BigTextString,FindString,ReplaceString), where it looks for
> the FindString and replaces it with ReplaceString in the BigTextString.
I'd be inclined to do away with the 'BigString'; there may be times you
don't know how big to make it. Here's what I use - just prototype to return
a STRING:
Replace PROCEDURE(STRING Text,STRING Find,STRING Replace,BYTE CS=FALSE)
Pos UNSIGNED,AUTO
RVal ANY ! Do not add ,AUTO
CODE
LOOP
Pos =
CHOOSE(~CS,INSTRING(UPPER(Find),UPPER(Text),1),INSTRING(Find,Text,1))
RVal = RVal & CHOOSE(~Pos,Text,Text[1 : Pos-1] & Replace)
Text = CHOOSE(~Pos,'',Text[Pos+LEN(Find) : LEN(Text)])
UNTIL ~Text
RETURN RVal
Jon.
Today is December 4, 2024, 2:52 am This article has been viewed 35398 times. Google search has resulted in 12 hits on this article since January 25, 2004.
|
|