VB读取TXT的问题

来源:百度知道 编辑:UC知道 时间:2024/05/16 22:04:01
比如说c:\1.txt内容如下
型号1 功能
11235 文字
11236 文字
11237 文字
型号2 功能
12358 文字
12359 文字
.......

我需要把里面的
12235
12236
12237
12358
12358
......
提取出来保存在c:\2.txt中
行前是“型号“等文字的行删除不要
后面的文字也不要
那位给个代码能完成

Private Sub form_click()
Open "z:\1.text" For Input As #1
Open "z:\2.text" For Append As #2
Do While Not EOF(1)
Line Input #1, s
x = Mid(s, 1, 5)
If IsNumeric(x) = True Then
Print #2, x
End If
Loop
Close #1
Close #2
End Sub

经我测试,很成功...

Private Sub Command1_Click()
Dim str As String, stem As String
Open "c:\1.txt" For Input As #1
Do Until EOF(1)
Line Input #1, str
Open "c:\2.txt" For Append As #2
If Left(str, 2) <> "型号" Then
stem = Mid(str, 1, Len(str) - 4)
Print #2, stem
End If
Close #2
Loop
Close #1
End Sub

标准答案,楼上的都不行..哈哈:

Private Sub Command1_Click()
Dim ST As String
Dim SP As Variant
Open "C:\1.txt" For Input As #1
Open "C:\2.txt" For Output As #2
Do W