开发者

Delete not specific lines in a text file

开发者 https://www.devze.com 2023-02-05 15:39 出处:网络
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.

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())
0

精彩评论

暂无评论...
验证码 换一张
取 消