luvcloud
June 28th, 2002, 12:27 AM
in file I/O, is it possible to read from a file, search for particular string of text and if found, replace that text with another different text?
|
Click to See Complete Forum and Search --> : file I/O luvcloud June 28th, 2002, 12:27 AM in file I/O, is it possible to read from a file, search for particular string of text and if found, replace that text with another different text? Manish Malik June 28th, 2002, 01:59 AM Talking about doing that in the same file (i.e. without creating a new file, writing changed contents to it, and then replacing the old file by it), this can be done very easily if the two strings are of the same length, so you can move to the specified point in file, and overwrite it with the new string. luvcloud June 28th, 2002, 02:07 AM how do i search for the specific text then? can u show me an example? jparsons June 28th, 2002, 07:51 AM Originally posted by luvcloud how do i search for the specific text then? can u show me an example? Read the file a line at a time in a loop and search every line for the string. jcurbina June 29th, 2002, 08:59 PM Why don't you use a Stream class and take advantage of its methods (Read, Write, etc.) to handle the files. Using this you could easily find and replace strings in the file. Look at the examples in the QuickStart Help. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |