Inserting Text into a Text File


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Inserting Text into a Text File

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Inserting Text into a Text File

    [Originally posted by Sean Naghibi]

    I am writing a utility in VB which opens a text file say:

    sample.txt

    and inside the file we have the following:

    3
    0
    "none"
    "Sample1"
    "Abc"
    False
    "Sample 2"
    "123"
    False
    "Sample3"
    "Abc"
    True
    "1"
    "2"
    "3"
    "4"
    "5"
    "6"
    RW

    what I need it to do is to count line 12 and if it is True then
    insert the following

    ""
    ""
    ""
    ""
    ""
    ""
    in line 19

    I would be greatful if anyone could help me.

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Inserting Text into a Text File

    [Originally posted by Greg DeBacker]

    The easiest way to do this is to open the first file and read it line by line. At the same time open a new, temp file (you can name it anything) and write each line to the temp file. When you get to line 12 (or whatever) you then start writing the empty quotes to the temp file. Then continue reading the remainder of the original file and write to the temp file after the empty quotes. When all is done the temp file should look just like the original except that it has the new lines added to it. You can then delete the original file and rename the temp file giving it the name of the original file.

    Grex

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center