1. Re: Replacing characters (Matt: bug)
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Sep 16, 2002
- 459 views
Thanks Matt! Dan ----- Original Message ----- From: "Matthew Lewis" <matthewwalkerlewis at YAHOO.COM> To: "EUforum" <EUforum at topica.com> Subject: RE: Replacing characters (Matt: bug) > > > > -----Original Message----- > > From: Dan Moyer [mailto:DANIELMOYER at prodigy.net] > > > I've been using your useful replace_all function, & found > > that if I happen > > to try to replace the last character on a line it errors. > > Sure does. Guess I never tried to do that. Add the if statement around the > call to match() in the loop: > > function replace_all( sequence text, object a, object b ) > integer ix, jx > > if atom(a) then > a = {a} > end if > > if atom(b) then > b = {b} > end if > > ix = 0 > jx = match( a, text ) > while jx do > ix += jx > text = text[1..ix-1] & b & text[ix+length(a)..length(text)] > ix += length(b) > > if ix < length(text) then > jx = match( a, text[ix+length(a)..length(text)] ) > else > jx = 0 > end if > end while > > return text > end function > > > >