You have to rewrite the entire file:
Dim newLines = File.ReadAllLines(path).
.Where(Function(l) Not l.Trim.Equals(stN, StringComparison.OrdinalIgnoreCase) )
File.WriteAllLines(path, newLines)
If you don't want to use Trim and the case insensitive comparison:
.Where(Function(l) l <> stN)
Edit: Are you using .NET 3.5? Then File.WriteAllLines
does not accept an IEnumerable(Of String)
but only String()
. You need to create one from the query:
File.WriteAllLInes(path, newLines.ToArray())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…