Solved

Faster Parsing

Posted on 2002-07-20
5
247 Views
Last Modified: 2010-05-02
OK.  I parse HTML.

A lot of it.
I need to make this procedure faster--

I think that i need to track which letters are the most popular and then make a complex select statement sorted in the order of most popular->least popular.

But thats just a detail; its not the meat and bones.

i wanna keep this statement simple and quick.

i think that most of my performance hit is on the repeated ASC()-- i think that maybe i should build a collection of ASCII symbols..  (but to be honest i dont know how to do a collection (but i can do an array))

and I would like to
a). optimize my code for speed
b). find a replacement for the Asc(function)

My Code
________________________________________________
Option Explicit

private newString

Public Sub CleanString(strIncoming As String)
On Error GoTo errhandler

newString = ""

'Determine length of string
Dim i As Integer
Dim strLen As Integer
Dim char As String
Dim ascChar As Integer

strLen = Len(strIncoming)
For i = 1 To strLen

char = Mid(strIncoming, i, 1)
ascChar = Asc(char)

If ascChar >= 46 And ascChar <= 57 Then
    newString = newString & char
  GoTo nextI
End If

If ascChar >= 63 And ascChar <= 90 Then
    newString = newString & char
  GoTo nextI
End If

If ascChar >= 97 And ascChar <= 122 Then
    newString = newString & char
  GoTo nextI
End If

newString = newString + " "
nextI:
Next i

cleanexit:
Exit Sub

errhandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly
Resume Next
Resume cleanexit
End Sub
___________________________________

other information-

i am making this a class and compiling into a DLL(so that i can move to COM+ down the road (or COM.net or whatever its called))
0
Comment
Question by:__Holly__
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 1

Author Comment

by:__Holly__
ID: 7166979
oh and what i do in the next step is to split this into an array based on a space.

i should move that split function back into this--

but its a mute point until i can get this running faster...
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 350 total points
ID: 7167129
My tests show this to be almost 20 times faster.

Public Function fCleanString2(strIncoming As String) As String
    Dim sngTime As Single
    Dim bytIn() As Byte
    Dim bytOut() As Byte
    Dim i As Long
   
    sngTime = Timer
'    On Error GoTo errhandler
   
    bytIn = StrConv(strIncoming, vbFromUnicode)
    ReDim bytOut(LBound(bytIn) To UBound(bytIn))
   

   
   
    For i = 0 To UBound(bytIn)
        Select Case bytIn(i)
        Case 46 To 57, 63 To 90, 97 To 122
            bytOut(i) = bytIn(i)
        Case Else
            bytOut(i) = 32 'space
        End Select
    Next i
    fCleanString2 = StrConv(bytOut, vbUnicode)
    Debug.Print "fCleanString2 " & Timer - sngTime
    Exit Function
   
errhandler:
    MsgBox Err.Number & " - " & Err.Description, vbOKOnly
    Resume Next
   
End Function
0
 
LVL 1

Author Comment

by:__Holly__
ID: 7168211
thanks paul ill test that out.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7172333
This was my best, but I think it's still about 4 times slower than Paul's

Public Function fCleanString3(strIncoming As String) As String
Dim vStart
Dim vEnd
Dim i
Dim strTemp

    vStart = GetTickCount
    strTemp = strIncoming
     
   For i = 0 To 255
        If (i < 46) Or (i > 57 And i < 63) Or (i > 90 And i < 97) Or (i > 122) Then
            strTemp = Replace(strTemp, Chr(i), " ")
        End If
   Next i
   
   fCleanString3 = strTemp
   vEnd = GetTickCount
    Label1.Caption = "Elapsed Milli-seconds: " & (vEnd - vStart)

   Exit Function
   
errhandler:
   MsgBox Err.Number & " - " & Err.Description, vbOKOnly
   Resume Next
   
End Function
0
 
LVL 1

Author Comment

by:__Holly__
ID: 7173686
i didnt have the chance to run performance tests/determine a ratio--

but it sure seems a lot faster.

thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question