如何删除使用过的字符串 [英] How to remove a used string
本文介绍了如何删除使用过的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,我想删除用户使用的 .txt 文件中的字符串.这是为了使其无法使用.
Now, I want to remove the string in the .txt file that the user used. This is to make it invalid for use.
感谢 Tim Schmelter 的 更正代码.
If .txt file.Contains(stN) Then
'Do anything here
'Then I want to remove the string used.
End If
推荐答案
你必须重写整个文件:
Dim newLines = File.ReadAllLines(path).
.Where(Function(l) Not l.Trim.Equals(stN, StringComparison.OrdinalIgnoreCase) )
File.WriteAllLines(path, newLines)
如果您不想使用 Trim 和不区分大小写的比较:
If you don't want to use Trim and the case insensitive comparison:
.Where(Function(l) l <> stN)
编辑:您使用的是 .NET 3.5 吗?然后 File.WriteAllLines
不接受 IEnumerable(Of String)
而只接受 String()
.您需要从查询中创建一个:
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())
这篇关于如何删除使用过的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文