We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,307 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

QBasic character counter - helped by Buff

0
By Tom Pilk on Jan 1st, 2005 6:21 pm

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.

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

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

Dani
The Queen of DaniWeb
Administrator
21,553 posts since Feb 2002
Reputation Points: 1,555
Solved Threads: 376
Skill Endorsements: 124

The Len() function is all you really need

rhenerlau
Newbie Poster
9 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.5237 seconds using 2.63MB