Re: Replacing characters
- Posted by Irv Mullins <irvm at ellijay.com> Feb 01, 2002
- 428 views
On Friday 01 February 2002 05:00 pm, Marcus wrote: > How do you search and replace characters in a sequence? > > I need to replace \ with \\ and vice versa. > You can create a sequence containing the locations of any matching characters, and then replace those: -- lightly tested :p sequence text, matches atom pattern, replacement puts(1,"Enter a string:\n") text = gets(0) pattern = '\\' -- have to escape a backslash replacement = '@' matches = {} for i = 1 to length(text) do if text[i] = pattern then matches &= i end if end for ? matches -- see the list of places that matched for i = 1 to length(matches) do text[matches[i]] = replacement end for puts(1,text) Regards, Irv