VB文本筛选问题

来源:百度知道 编辑:UC知道 时间:2024/08/20 21:36:10

answer.txt内容
[F1]XXXXXXXX
[F2]XXXXXXXX
[F2]XXXXXXXX
[F2]XXXXXXXX
这个[F1]只是个书签形式的,只读取[F1]行后面的XXXXXX内容。
Private Sub Command1_Click()
FindKeyword "[F1]" '搜索关键字
End Sub

Sub FindKeyword(ByVal kw As String)
Dim Keyword$()
Dim Stream$, filepath$
Keyword = Split(kw, " ")
filepath = IIf(Right$(App.Path, 1) <> "\" And Right$(App.Path, 1) <> "/", App.Path & "\answer.txt", App.Path & "answer.txt")
Text2.Text = ""
Open filepath For Input As #1
Do While Not EOF(1)
Line Input #1, Stream
For i = 0 To UBound(Keyword)
If InStr(Stream, Keyword(i)) = 0 Then
Exit For
'ReDim Keyword(1)
Else
If i = UBound(Keyword) Then
Text2.Text = Text2.Text & " " & Stream & vbCrLf
End If
End If

Next
Stream = ""
Loop
Cl

这个代码写的很好啊,不知道你到底啥问题
你要是只保留[F1]后面的内容,那你就用“[F1]”做关键字搜索就行了!
这个代码支持你用多个关键字以空格分隔搜索内容!!

明白了,你只要[F1]后面的内容,而不包含关键字"[f1]"是不是,该一点点就行了:
Private Sub Command1_Click()
FindKeyword "[F1]" '搜索关键字
End Sub

Sub FindKeyword(ByVal kw As String)
Dim Keyword$()
Dim Stream$, filepath$
Keyword = Split(kw, " ")
filepath = IIf(Right$(App.Path, 1) <> "\" And Right$(App.Path, 1) <> "/", App.Path & "\answer.txt", App.Path & "answer.txt")
Text2.Text = ""
Open filepath For Input As #1
Do While Not EOF(1)
Line Input #1, Stream
For i = 0 To UBound(Keyword)
If InStr(Stream, Keyword(i)) = 0 Then
Exit For
'ReDim Keyword(1)
Else
If i = UBound(Keyword) Then
Text2.Text = Text2.Text & " " & mid(Stream,5) & vbCrLf '这里改一点点就行了
End If
End If

Nex