home *** CD-ROM | disk | FTP | other *** search
- "Sub Main()
-
- Str1 = ""Welco me to VB Script. The s imp lest language ""
- Str1 = Str1 & ""for scripting your VB applications.""
- Str1 = Trim(Str1)
-
- position = 1
- ' massage string:
- ' replace line feeds with spaces
- Str1 = Replace(Str1, Chr(13) & Chr(10), "" "")
- ' replace tabs with single spaces
- Str1 = Replace(Str1, Chr(9), "" "")
- Str1 = Trim(Str1)
- ' Count the first word
- ' Because the last word isn't delimited by
- ' a space, if the string isn't blank, then it
- ' contains at least one word.
- ' By setting words=1, we won't have to increase the
- ' number of words by 1 when we are done counting.
- If Len(Str1) > 0 Then words = 1
- ' while the string contains spaces...
- Do While position > 0
- position = InStr(position, Str1, "" "")
- ' ... increase word count
- If position > 0 Then
- words = words + 1
- ' and skip additional spaces
- While Mid(Str1, position, 1) = "" ""
- position = position + 1
- Wend
- End If
- Loop
- Show ""The string contains "" & words & "" words""
-
- End Sub "
-