Home > How-To Library > String Manipulation
How to count the number of spaces in a string
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** ' 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
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.