如何使用 vb 写入文本文件中的特定行
我有一个包含此示例数据的文本文件
绑架测试|1
芯片测试|2
帽子测试|3
邪恶测试|4
我想知道如何循环它以找到用户并删除该行。
这是我到目前为止所拥有的:
Public Sub RemoveMember(member As String)
Dim u As String, strdata() As String
Open (App.Path & "\Membership.txt") For input As #1
Do
input #1, u
strdata = Split(u, "|")
If strdata(0) = member Then
'figure out a way to remove this line from the text file'
End If
Loop Until EOF(1)
Close #1
End Sub
I have a text file with this sample data
abduct test|1
chip test|2
hatter test|3
evil test|4
I would like to know how I could loop through it to find a user and remove that line.
This is what I have so far:
Public Sub RemoveMember(member As String)
Dim u As String, strdata() As String
Open (App.Path & "\Membership.txt") For input As #1
Do
input #1, u
strdata = Split(u, "|")
If strdata(0) = member Then
'figure out a way to remove this line from the text file'
End If
Loop Until EOF(1)
Close #1
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会说:
Stefan 的方法可能更快,但如果文件变得非常大,则会使用大量内存。
我不熟悉VB的本地文件方法。使用 FileSystemObject(参考 Microsoft Scripting Host),您将得到:
无需 IDE 的帮助即可编写,因此代码中可能存在一些拼写错误。
I would say:
Stefan's method is probably faster but will use a lot of memory if the file grows very large.
I am not familiar wityh VB's native file method. Using FileSystemObject (reference Microsoft Scripting Host) you wil get:
Written without the help of the IDE, so there may a few typos in the code.