Looking for the best way to do this in VB6. Typically, I would use this approach…
' count spaces
For i = 1 To Len(text)
If Mid$(text, i, 1) = " " Then count = count + 1
Next
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would use a modified bucket sort:
…and your result is in
count. The performance is O(N) – ifMid$is O(1).Edit:
Based on your clarification, do this:
As ascii compares have to be faster that string comparison. I’d profile it just in case, but I’m pretty sure.