gpt4 book ai didi

string - 如果该行包含一些字符串,则从文本文件中删除该行

转载 作者:行者123 更新时间:2023-12-01 11:04:04 25 4
gpt4 key购买 nike

在 VB6 中,如果该行包含一些字符串,我正在寻找一种方法从文本文件中删除该行文本。我主要使用 C# 工作,但我在这里不知所措。使用 .NET 有多种方法可以做到这一点,但我是幸运的人,我必须维护一些旧的 VB 代码。

有没有办法做到这一点?

谢谢

最佳答案

假设您在变量 sFileName 中有文件名:

Dim iFile as Integer
Dim sLine as String, sNewText as string

iFile = FreeFile

Open sFileName For Input As #iFile
Do While Not EOF(iFile)
Line Input #iFile, sLine
If sLine Like "*foo*" Then
' skip the line
Else
sNewText = sNewText & sLine & vbCrLf
End If
Loop
Close

iFile = FreeFile
Open sFileName For Output As #iFile
Print #iFile, sNewText
Close

您可能希望输出到不同的文件而不是覆盖源文件,但希望这能让您更接近。

关于string - 如果该行包含一些字符串,则从文本文件中删除该行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7855588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com