01-12-2004, 06:48 PM
01-12-2004, 07:14 PM
Topic is rather insulting.
Count the spaces.
Count the spaces.
01-12-2004, 07:15 PM
OK...
^Untested
EDIT: Works.
Code:
yourstr$="your stuff here"
spaceCount=1
FOR i=1 to LEN(yourstr$)
IF MID$(yourstr$,i,1)=" " THEN spaceCount=spaceCount+1
NEXT
PRINT spaceCount
EDIT: Works.
01-12-2004, 08:54 PM
zack, you might as well have just emailed that to his teacher.
01-12-2004, 10:05 PM
Sorry, sorry...
Seraph, think it over and make sure you understand it all before you hand it in. :roll:
Seraph, think it over and make sure you understand it all before you hand it in. :roll:
01-13-2004, 03:31 AM
It doesn't work completely anyway... what about sentences with double spaces? I had to make a proggie like this for comp sci, and it's a bit trickier than it looks...
01-13-2004, 04:10 AM
Ah, well, I was assuming things are single-spaced...I can integrate it to ignore a space right after another.
OK, here, it deals with double-spacing:
OK, here, it deals with double-spacing:
Code:
yourstr$ = "your stuff here. and cool yay"
spaceCount = 1
FOR i = 1 TO LEN(yourstr$)
IF MID$(yourstr$, i, 1) = " " THEN
spaceCount = spaceCount + 1
IF MID$(yourstr$, i + 1, 1) = " " THEN i = i + 1
END IF
NEXT
PRINT spaceCount
01-13-2004, 06:50 PM
Code:
MyStr$ = "your stuff here. and cool yay"
spaced% = 0
spaces% = 1
FOR I% = 1 TO LEN(MyStr$)
z$ = MID$(MyStr$, I%, 1)
IF z$ = CHR$(32) AND NOT(spaced%) THEN
spaces% = spaces% + 1
spaced% = -1
ELSEIF MID$(MyStr$, I%, 1) <> CHR$(32) THEN
spaced% = 0
END IF
NEXT I%
IF RIGHT$(MyStr$, 1) <> CHR$(32) THEN spaces% = spaces% - 1
PRINT "Number of words ="; spaces%
I think this flag-theory is better instead of front-scan theory
01-13-2004, 08:59 PM
Why?
That way works too, but...is it faster? I don't really see improvement.
That way works too, but...is it faster? I don't really see improvement.
Anonymous
01-15-2004, 12:30 AM
its because his code is 'dynamic' that is, it can handle *any* number of spaces. yours can only handle double spacing. IMO, its always better to write code that is universal...