Joe Strazzere - All Things Quality

Visit my new blog at http://strazzere.blogspot.com/


December 1, 2005 - WinTask - WordCount

Posted in WinTask

'
' WordCount - Count the number of words in a string

' Author: Joe Strazzere

'

a$="This is a test of the early warning system, here.  How well does it work?"

a$=Trim$(a)
i=1

pos=instr(a$," ")

While pos > 0
    i=i+1
    a$=Ltrim$(Mid$(a$,pos,Len(a$)))
    pos=instr(a$," ")
Wend

msgbox(str$(i))

 

Note that this is NOT the same as the value returned by the SplitIntoArray() function.

The WordCount snippet doesn't care if there are many spaces between words, while SplitIntoArray() does.

 

'
' Compare WordCount and SplitIntoArray
'
DIM testarray$(100)


a$=InputBox$("Enter a string", "Compare WordCount and SplitIntoArray", " This is just-a-test     ")
'a$="This  is      a test of the early warning system, here.   How well does it work?"
i=1
b$=a$

a$=Trim$(a$)
pos=instr(a$," ")

While pos > 0
   i=i+1
   a$=Ltrim$(Mid$(a$,pos,Len(a$)))
   pos=instr(a$," ")
Wend


valu=SplitIntoArray(b$,testarray$())

msgbox("["+b$+"]"+CRLF+CRLF+"WordCount sees "+str$(i)+" words."+CRLF+CRLF+"SplitIntoArry sees "+str$(valu)+" words.")


<- Last Page :: Next Page ->

About Me

A gathering place for information and ideas about Quality Assurance, Testing, and other useful topics.

Problems cannot be solved by the same level of thinking that created them. - A. Einstein

Search This Site

Translate This Site

RSS Feed

Subscribe

Twitter

@jstrazzere

Categories

Life
QA
Sports
Tools
WinTask
Work in General

What I'm Reading Now