3.搜索字符串

给出一个文本文件 test.txt

Ford
Jeep
Honda

以下脚本正在处理此文本文件:

'Read in File Data to an array, separate by newline vb equivalent (vbcrlf)
Dim car, cars
Dim filefullname : filefullname = "C:\testenv\test.txt"
cars = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(filefullname, 1).ReadAll, vbcrlf)

'Exact Match search. 
Dim searchstring : searchstring = "Jeep"
For Each car In cars
    If Car = searchstring Then Exit For
Next

'Partial Match search
'Instr returns >0 if any result is found, if none, InStr returns -1
'The If statement will use -1 = false, >0 = true
Dim searchstring : searchstring = "Jee"
Dim position
For car = 0 To ubound(cars)
    If InStr(cars(car), searchstring) Then 
        position = car
        Exit For
    End If
Next