Thread: how to overwrite the text in *.txt

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    how to overwrite the text in *.txt

    Hi:
    how to overwrite the old data in *.txt with only little steps, I did somehow in a very complicated way.

    thanx
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    I guess the easiest way for small files would be read it all into one string, replace what you need, and write it all back.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    NVoigt,

    What is the best approach for big files? Should I still read, edit and write? How could I seach for a string, position there, and overwrite that string? Any ideas?????

    Thanks,
    Kendal

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Replacing a string in a file is always messy, because you can only do this if the strings lengths' match. Therefore, I would suggest reading the input file line by line, replacing in each line and writing it back to a seperate output file. Once this is done, the input can be deleted and the output renamed to the former input.

    If your replacement can span more than one line, the reading/writing part becomes a bit tricky, but basically, the input, copy, delete, rename output would stay the same.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    184
    Gotcha,
    I appreciate it.
    Thanks again,
    Kendal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble drawing text xlib.
    By Qui in forum Linux Programming
    Replies: 1
    Last Post: 05-10-2006, 12:07 PM
  2. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 09:52 PM
  3. Text positioning and Text scrolling
    By RealityFusion in forum C++ Programming
    Replies: 3
    Last Post: 08-13-2004, 12:35 AM
  4. Scrolling The Text
    By GaPe in forum C Programming
    Replies: 3
    Last Post: 07-14-2002, 04:33 PM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM