When you need to process each character in a string, you can assign the string to a byte array and iterate on its elements (remember: each Unicode character corresponds to two bytes). This approach is usually much faster because it saves a lot of Mid$ functions and, hence, a lot of temporary strings. Here is a very fast way to count the spaces in a string:
Dim b() as Byte, count As Integerb() = source$For i = 0 to UBound(b) Step LenB("A") If b(i) = 32 Then count = count + 1Next
Note the unorthodox usage of the LenB() function: it returns 2 under VB4/32, VB5 and VB6, and 1 under VB4/16, so that you can use the same code fragment without the need for a #If compiler directive.
Beware: this technique might not work if you then localize your code for foreign countries that make use of the full Unicode character set.