VB读取文本指定信息

来源:百度知道 编辑:UC知道 时间:2024/06/02 10:57:40
aaa XXXXX XXXXXXX
我想得到aaa那行,第二个空格和第三个空格之间的文本。
C:\1.txt

open "c:\1.txt" for input as #1
do while not eof(1)
line input #1,s
if left(s,3)="aaa" then
exit do
end if
loop
close #1
s=split(s," ")
msgbox s(2)

代码如下。
============
Private Sub Form_Load()
Open "c:\1.txt" For Input As 1
Dim s As String
Do Until EOF(1)
Line Input #1, s
If Left(s, 3) = "aaa" Then
MsgBox Split(s)(2)
End If
Loop
Close
End Sub

用line input。。