Re: I need help! (again :>)
- Posted by Michael Bolin <michaeltom at GEOCITIES.COM> Jun 02, 1997
- 984 views
> I'm writing a program to read in a file and change certain pieces of > text to something else. For instance in the file I would change all > instances of '1' to '2'. However when I try to "find" the text I want > to change in my sample file it returns 0. Can anyone help? There are several bugs in your main loop. Replace it with this one, and it should work: for i = 1 to length(file) do n = find('1', file[i]) if n != 0 then x = file[i][1..n-1] & '2' & file[i][n+1..length(file[i])] file[i] = x end if end for You need to search for an atom ( '1' ), not a sequence ( "1" ). Also, if the value is not found, find() will return 0, not -1. Lastly, your replace routine is written incorrectly. The simple loop above will work instead. Regards, Michael Bolin