Re: String Search and Replace
- Posted by Jay Daulton <JayD at ADVANCEDBIONICS.COM> Nov 12, 1999
- 475 views
Thanks - I will give it a try. Jay Daulton -----Original Message----- From: Brian K. Broker [mailto:bkb at CNW.COM] Sent: Friday, November 12, 1999 3:12 PM To: EUPHORIA at LISTSERV.MUOHIO.EDU Subject: Re: String Search and Replace Here is a simple example I just whipped up: -- tested code starts here -- sequence string1, string2 function replace( sequence string, sequence findstring, sequence replacestring ) integer loc, len len = length( findstring ) loc = match( findstring, string ) if loc then return string[1..(loc - 1) ] & replacestring & string[ (loc + len)..length( string ) ] else return string end if end function string1 = "Euphoria is fast, flexible and fun; simple, safe, and sexy!\n" string2 = replace( string1, "sexy", "super sexy" ) puts( 1, string1 ) puts( 1, string2 ) -- end tested code -- Sorry about lack of comments but it should be pretty straight-forward. If the sequence is not found, the function simply returns the original, unmodified string. You can modify it to return whatever you want... Hope this helps, Brian