This is a little program in QBasic which counts the number of characters in a string. Made by Buff - two errors removed by me. Thanks Buff.

97 Views
DECLARE SUB GetWords (st$, wds%)

st$ = "Hello my name is John Doe"
IF RIGHT$(st$, 1) <> " " THEN st$ = st$ + " "
FOR k% = 1 TO LEN(st$)
IF MID$(st$, k%, 1) = " " THEN words% = words% + 1
characters% = characters% + 1
NEXT
PRINT "total characters="; characters%
PRINT "total words="; words%


xst$ = "Hello my name is John Doe"
GetWords xst$, words%
PRINT "words= "; words%

SUB GetWords (st$, wds%)
IF RIGHT$(st$, 1) <> " " THEN st$ = st$ + " "
FOR k% = 1 TO LEN(st$)
IF MID$(st$, k%, 1) = " " THEN words% = words% + 1
characters% = characters% + 1
NEXT
'print "total characters=";characters%
'print "total words=";words%
wds% = words%
END SUB

About the Author
Member Avatar Tom Pilk Newbie Poster

In a nutshell? What is this website on about!?!? I don't live in a nutshell - i've already told you I live in a tree - a beech to be precise Mr. Sherlock. Oh and what is blurb supposed to mean? It sounds like some sort of animal. Oh well,
TP

Dani 1,954

Thank you ... and thank Buff. Who is Buff ;)

rhenerlau

The Len() function is all you really need