PDA

Click to See Complete Forum and Search --> : How to find/search and extract FAST


vesaj
Nov 2nd, 1999, 12:35 AM
How do I find and extract strings from large strings/files (+100kB) f-a-s-t ? I've tried the RichTextBox.Find() and InStr() methods. They work fine when you search in smaller text, but when the string is big... :(

Example...

Sub TooSlow()

Dim i As Long
Dim j As Long

i = RichTextBox1.Find("<a href", , , rtfNoHighlight)
While i > -1
j = RichTextBox1.Find("</a>", i + 7, , rtfNoHighlight)
If j > -1 Then
' do stuff (a = mid(RichTextBox1,i,j) for example
Else
Exit Sub
End If
i = RichTextBox1.Find("<a href", j + 4, , rtfNoHighlight)
Wend
End Sub


Repeating the sub routine ten times is three times faster than calling it once with a ten times larger string...

smalig
Nov 2nd, 1999, 01:15 AM
If you don't need to display file you can simply open these file and looking for string.

Dim fileline$, searchline$

Open "FILE.TXT" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
Input #1, fileline
If Instr(fileline, searchline)>0 Then MsgBox "I'm find my string!"
Loop
Close #1 ' Close file.

Best regards.

------------------
smalig
smalig@hotmail.com
smalig.tripod.com (http://smalig.tripod.com)