|
|
|
When you need to count how many occurrences of a given character are in a string, you might be tempted to go along the "traditional" Visual Basic way: |
Everything is easier if you use the capability to move a string into a Byte array. Here is a complete routine: ' count spaces |
Click here to copy the following block | Function CountSpaces(ByVal sText As String) As Long Dim bArr() As Byte Dim i As Long Dim count As Long bArr() = sText For i = 0 To UBound(bArr) Step 2 If bArr(i) = 32 Then count = count + 1 Next CountSpaces = count End Function |
This approach can be up to three times faster than the traditional one.
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|