Lightning Fast Word Counting
A small ultra-fast function used to count the number of words in a string.
AI
Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Zdrojový kód
' © Christopher Lucas 2001
' You may freely use and distribute this code
' in all your applications. Recognition is
' appreciated though.
Public Function WordCount(Text As String) As Long
Dim dest() As Byte
Dim i As Long
If LenB(Text) Then
' Move the string's byte array into dest()
ReDim dest(LenB(Text))
CopyMemory dest(0), ByVal StrPtr(Text), LenB(Text) - 1
' Now loop through the array and count the words
For i = 0 To UBound(dest) Step 2
If dest(i) > 32 Then
Do Until dest(i) < 33
i = i + 2
Loop
WordCount = WordCount + 1
End If
Next i
Erase dest
Else
WordCount = 0
End If
End Function
Původní komentáře (3)
Obnoveno z Wayback Machine