Valhalla Legends Forums Archive | Visual Basic Programming | Search text files

AuthorMessageTime
BreW
Is there any efficient and easy way to find a certain string in a file besides....
[code]
Dim asdf$
Open file For Input As #1
Do Until EOF(1)
Line Input #1, asdf
If asdf = "string" Then Goto Lol
Loop
Lol:
Close #1
[/code]
which is what i have been using for all the while?
March 20, 2007, 11:57 PM
Myndfyr
Yes, you can use Regular Expressions.  Take a look at http://visualbasic.about.com/od/usingvbnet/l/blregexa.htm for a brief stint in their use in VB6 as well as http://www.regular-expressions.info/vb.html which as a site is a great reference for regex.

Regular expressions are also supported by the Microsoft .NET Platform and are consequently available in Visual Basic .NET.
March 21, 2007, 12:07 AM
Barabajagal
Or load the entire file using binary access read, and then use instr.
March 21, 2007, 12:25 AM
BreW
Myndfyre, thanks for helping. RegExs look very interesting and i might use that... but it would still require me to open the file as binary in order to use it. and that's basically what reality said......
[quote author=[RealityRipple] link=topic=16512.msg166933#msg166933 date=1174436702]
Or load the entire file using binary access read, and then use instr.
[/quote]
because somewhere in that article it goes on to state how InStr() and Like() (like is good, but it's only for ranges of ascii characters) are the only two native VB6 regex functions. SO my best bet is to do what reality said, open it in binary and use InStr() until i find more documentation about and gain deeper knowledge of regexes.
March 21, 2007, 1:08 AM
Barabajagal
Well, there is one ity bity problem with that method. Depending on the file you load, it will take more time, ram, and process usage.
March 21, 2007, 1:41 AM
UserLoser
[quote author=brew link=topic=16512.msg166934#msg166934 date=1174439313]
Myndfyre, thanks for helping. RegExs look very interesting and i might use that... but it would still require me to open the file as binary in order to use it. and that's basically what reality said......
[quote author=[RealityRipple] link=topic=16512.msg166933#msg166933 date=1174436702]
Or load the entire file using binary access read, and then use instr.
[/quote]
because somewhere in that article it goes on to state how InStr() and Like() (like is good, but it's only for ranges of ascii characters) are the only two native VB6 regex functions. SO my best bet is to do what reality said, open it in binary and use InStr() until i find more documentation about and gain deeper knowledge of regexes.
[/quote]

Note that Like isn't a function, it's an operator
March 21, 2007, 3:25 AM
BreW
Its a crazy one! Infact, too crazy to be considered an operator! heh... it should be a function though.
March 21, 2007, 2:23 PM

Search