CodeItBetter Programming Another VB Programming Blog

How to count the number of spaces in a string

Posted on October 22, 2011
1
2
3
4
5
6
7
8
9
10
11
'String Manipulation - How to count the number of spaces in a string
' NOTE: this function might not work with non-Latin alphabets.
Function CountSpaces(Text As String) As Long
    Dim b() As Byte, I As Long
    b() = Text
    For I = 0 To UBound(b) Step 2
        ' Consider only even-numbered items.
        ' Save time and code using the function name as a local variable.
        If b(I) = 32 Then CountSpaces = CountSpaces + 1
    Next
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.