Re: String Search and Replace
- Posted by Brian Broker <bkb at CNW.COM> Nov 16, 1999
- 496 views
On Fri, 12 Nov 1999 17:06:50 -0800, Jay Daulton <JayD at ADVANCEDBIONICS.COM> wrote: >I need to replace all matches without asking. That would be a minor change to my previous solution... Just use a recursive call on the remainder of the string: -- start code -- sequence string1, string2 function replace( sequence target, sequence old, sequence new ) integer len, loc len = length( old ) loc = match( old, target ) while loc do return target[1..(loc - 1) ] & new & -- recursive call on remainder of string -- replace( target[(loc + len)..length( target )], old, new ) end while return target end function string1 = "Euphoria is fast, flexible and fun; simple, safe, and sexy!\n" string2 = replace( string1, "and", "or" ) puts( 1, string1 ) puts( 1, string2 ) -- end code -- >Is there a library (maybe at >someone's website) of commonly used functions like search and replace, >different random number generators, probability distributions, misc. string >functions? The best place to look is http:\\www.rapideuphoria.com\ If you can't find it in recent user contributions or the archives, then you can try different Eu pages listed on "Other Euphoria Web sites". All other libraries come with the public domain version. -- Brian