VB删除文本中的特定内容
例如1.txt里有这些文本:#teststart123456abcd#testend789abcdefgqwertyuiop那么怎么删掉从#teststart到#test...
例如1.txt里有这些文本:
#test start
123
456
abcd
#test end
789
abcdefg
qwerty
uiop
那么怎么删掉从#test start到#test end里的内容呢?
注:#test start和#test end两行也得删 展开
#test start
123
456
abcd
#test end
789
abcdefg
qwerty
uiop
那么怎么删掉从#test start到#test end里的内容呢?
注:#test start和#test end两行也得删 展开
2个回答
展开全部
Private Sub Command1_Click()
Dim a() As Byte, Fn As String, s As String
Dim i, j
Fn = App.Path & "\1.txt"
If Dir(Fn) = "" Then Exit Sub
'读取文本内容
ReDim a(FileLen(Fn) - 1)
Open Fn For Binary As #1
Get #1, , a
Close #1
'删除指定内容
s = StrConv(a, vbUnicode)
i = InStr(1, s, "#test start", vbTextCompare)
j = InStr(i, s, "#test end", vbTextCompare)
j = InStr(j, s, vbNewLine, vbTextCompare)
s = Left(s, i - 1) & Mid(s, j + 2)
a = StrConv(s, vbFromUnicode)
'把删除后的内容重新写入文件
Kill Fn
Open Fn For Binary As #1
Put #1, , a
Close #1
End Sub
Dim a() As Byte, Fn As String, s As String
Dim i, j
Fn = App.Path & "\1.txt"
If Dir(Fn) = "" Then Exit Sub
'读取文本内容
ReDim a(FileLen(Fn) - 1)
Open Fn For Binary As #1
Get #1, , a
Close #1
'删除指定内容
s = StrConv(a, vbUnicode)
i = InStr(1, s, "#test start", vbTextCompare)
j = InStr(i, s, "#test end", vbTextCompare)
j = InStr(j, s, vbNewLine, vbTextCompare)
s = Left(s, i - 1) & Mid(s, j + 2)
a = StrConv(s, vbFromUnicode)
'把删除后的内容重新写入文件
Kill Fn
Open Fn For Binary As #1
Put #1, , a
Close #1
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询