7,785
社区成员




Dim s As String
Open "E:\tl-work\新建文件夹\R1201F02.nc" For Input As #1
N = 1
Do
Line Input #1, s
If InStr(1, s, "Z100.") And N > 100 Then
MsgBox "发现了:在第" & N & "行"
Exit Do
Else: N = N + 1
End If
Loop While Not EOF(1)
Close #1
Private Sub Command1_Click()
Dim StrA() As String
Dim X As Long
Dim keyText As String
'这里是要搜索的字符串
keyText = "12345"
'把Text1.Text的内容以换行为标志分割为字符串数组,每个数组元素就等于一行
StrA = Split(Text1.Text, vbCrLf)
'循环所有的行查询,起始行是100行开始,因为数组 StrA(0) 也是一行
For X = 99 To UBound(StrA)
If InStr(1, StrA(X), keyText) <> 0 Then
MsgBox "关键字找到在" & X + 1 & "行"
End If
Next X
End Sub
Dim s As String
Open "E:\tl-work\新建文件夹\R1201F02.nc" For Input As #1
n = 1
Do
Line Input #1, s
If InStr(1, s, "G00Z100.") Then
MsgBox "发现了:在第" & n & "行"
Exit Do
Else: n = n + 1
End If
Loop While Not EOF(1)
Close #1
line input 进来,instr判断是最简单的。根据俺的经验,速度并不慢。
dim s as string
open "a.txt" for input as #1
do
line input #1,s
if instr( 1, s, "11223344" ) then
debug.pring "发现了"
exit do
endif
loop while not eof(1)
close #1
Open "E:\tl-work\新建文件夹\R1201F02.nc" For Input As #1
Dim str1 As String, fstr2, nline As Long
str1 = Input(LOF(1), 1)
fstr2 = "ffd2"
nline = InStr(str1, fstr2)
Debug.Print "字符串所在行:" , nline - Len(Replace(Left(str1, nline), vbCrLf, " "))+1
Open "E:\tl-work\新建文件夹\R1201F02.nc" For Input As #1
Dim str1 As String, fstr2, nline As Long
str1 = Input(LOF(1), 1)
fstr2 = "ffd2"
nline = InStr(str1, fstr2)
Debug.Print "字符串所在行:" , nline - Len(Replace(Left(str1, nline), vbCrLf, " "))
Dim s As String
Open "E:\tl-work\新建文件夹\R1201F02.nc" For Input As #1
N = 1
Do
Line Input #1, s
If InStr(1, s, "Z100.") And N > 100 Then
MsgBox "发现了:在第" & N & "行"
Exit Do
End If
N = N + 1
Loop While Not EOF(1)
Close #1