Delete not specific lines in a text file
I'm looking for a way to delete lines that don't meet a criteria in VB.net. I'll just give a example of what I want done below.
Basically, I want the program to go through a text document (Each line) and if the line doesn't contain a certain string it would get erased.
Basically:
hgfhfghhfo TRUE
hdfgdfhdfh MAYBE
tytrteyuet POSSIBLE
ghjfgjgfjf FALSE
That's what the text document would look like, now I want it to not focus on the "RandomInfo" but on the "True/False" If it says TRUE I want it too keep the line. If the line contains anyth开发者_如何学编程ing except True I want it deleted. Can you guys help me with this?
Try this,
Dim filename = "sample.txt"
Dim result = From n In System.IO.File.ReadAllLines(filename).Where(Function(s) s.EndsWith("TRUE"))
System.IO.File.WriteAllLines(filename, result.ToArray())
精彩评论