• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help Me Plz.

 
sreekanth rach
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends, Help Me Plz.
How can i insert string at a particular location (say in 30th line) in a file say (named as abc.html).
Assume, that file "abc.html" already exists with 100lines of data.
Reply Soon,
Thanks in advance.
Kanth.
 
Tom Blough
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sreekanth,
You will need to open a temporary file, read a line from the file and write it to the temporary file stopping after 29 lines. Then write your new line to the temporary file, and resume reading lines from the original file and writing them to the temporary file until you reach the end of the original file.
This will ADD a line at line 30. If you want to REPLACE line 30, after you have written your new line to the temporary file, read the next line from the original file and discard it. Then resume reading and writing lines.
After you have finished, delete the original file, and then rename the temporary file to the original file name.

Tom Blough
[ March 13, 2004: Message edited by: Tom Blough ]
 
sreekanth rach
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Tom, for your great suggestion.
I got it. Thanks once again..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!