Word Count

Just starting out? Need help? Post your questions and find answers here.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Number of words

Code: Select all

numofwords.l = CountString(Trim("sentence to count the number of words in"), " ")+1
By the way, in traditional basic, the CountString() function is called Tally.
ebs wrote:Fred,

Would you consider adding something like the VB "Split" function? It fills an array with string fields separated by a specified delimiter. It's very handy for parsing words in a sentence and comma or tab delimited files.

Regards,
Eric
It's very handy, and that's why it's added already. It's called Field.
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Post by PB&J Lover »

Trond wrote:numofwords.l = CountString(Trim("sentence to count the number of words in"), " ")+1
That's very good. I'll use it, but it doesn't work if there are extra spaces in the line (which I often encounter). So I'll still remove them.

Here's my final procedure:

Code: Select all

Procedure.l WordCount(Text$)
ProcedureReturn CountString(Trim(RemoveExtraSpaces(Text$))," ") + 1
EndProcedure
Thanks.
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
Post Reply