Does anyone know how to count the number of characters words in a string or in anything in QBasic? I'm trying to make a hangman game and I have a list of all my words but i need to find out how to count characters for the blank spaces, you know. I would be grateful if anyone has any section of code, thanks,
TP :confused:
Tom Pilk
0
Newbie Poster
Recommended Answers
Jump to PostSt$="Hello my name is John Doe"
if right$(st$)<>" " 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%(in a sub)
declare sub getwords(st$,wds%)
xst$="Hello my name is John Doe"
GetWords xst$,words%
print "words= ";words%SUB GetWords(st$,wds%)
…
Jump to PostThat doesn't seem to work. It needs a comma in:
if right$(st$)<>" " then st$=st$+" "
and when you put it in it seems to need an expression?
Any clues?!?
Thanks
TP :rolleyes:Sorry, should be
if right$(st$,1)....
All 5 Replies
Buff
0
Light Poster
Tom Pilk
0
Newbie Poster
Buff
0
Light Poster
Tom Pilk
0
Newbie Poster
bs64
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.