how to delete the lines from txt files in vb
how to delete the lines from txt files in vb
Collapse
X
-
Tags: None
-
You'd have to read the text file into VB line by line, write them out line by line & filter out the stuff you don't want.
The new file would be a Temp.Txt file.
The original file would be renamed/deleted & the Temp.Txt file renamed to the original.Last edited by Killer42; Jul 3 '07, 09:36 AM. Reason: Remove caps from all the words, leaving 'sentence case'. -
Note that there are various ways in which you could approach this.
For instance, you could read the entire file into a string array, then write it back out, overwriting the same file and simply skipping lines you don't want. This is a slightly risky technique because as soon as you start writing, you have zapped the original file. If anything goes wrong before you finish, you may have lost your data file.
The safer, and probably more widely-used technique, is to read your input file and write the modified data to a another file - often a temporary file (as SkinHead suggested). Then depending on what you want, you can keep or delete the original file. One common technique used by many applications is to write out a temporary file with some made-up name, then delete the old file, then rename the new file to the original name. There are still things which can go wrong, but the risk, are reduced.Comment
Comment