Discuss Scratch

DogeTheKitten
Scratcher
54 posts

Word counter

How do I find the number of words in an answer, like the:
askandwait
block? like if the answer was “hello world”, how would I count the words?

Last edited by DogeTheKitten (Feb. 28, 2018 17:37:50)

KingOfAwesome58219
Scratcher
1000+ posts

Word counter

Go through a string, adding every letter to the same line. When you encounter a space, add a new line and start adding to that instead. Remove all blank values in the list, and just use the length of the list.
Here's an example:
definewordCount=numberofwordsininputdeleteallofcountsetito0 keeps track of what letter we're atrepeatlengthofinputchangeiby1ifletteriofinput= thenaddtocount this is blank, not a spaceelsereplaceitemlastofcountwithjoinitemlastofcountletteriofinput that's a space (" ")setito1repeatlengthofcountifitemiofcount= thendeleteiofcount that's a spacechangeiby1setwordCounttolengthofcount




Last edited by KingOfAwesome58219 (Feb. 28, 2018 18:38:37)

gor-dee
Scratcher
1000+ posts

Word counter

here's what I did
whenclickedaskWhat's your name?andwaitsetword countto0setito1repeatuntilnotletteriofanswer= ori=lengthofanswerchangeiby1repeatuntili=lengthofanswerrepeatuntilletteriofanswer= ori=lengthofanswerchangeiby1changeword countby1repeatuntilnotletteriofanswer= ori=lengthofanswerchangeiby1
it doesn't separate the words and put them in a list, just gives you a word count. It should work even if the answer has multiple spaces at the beginning, middle or end which I think might break the example above (although I haven't tested it)

Last edited by gor-dee (Feb. 28, 2018 21:34:20)

Dabman2392
Scratcher
100+ posts

Word counter

Last edited by Dabman2392 (Dec. 17, 2020 17:24:31)

potatohead_1011
Scratcher
100+ posts

Word counter

Please

Dabman2392 wrote:

please don't necropost
Dabman2392
Scratcher
100+ posts

Word counter

If you are using it to make noises for the amount of characters that there are in an answer, then, use this:
repeatlengthofanswerplaysoundpop

Last edited by Dabman2392 (Dec. 17, 2020 17:45:47)

Dabman2392
Scratcher
100+ posts

Word counter

Otherwise, use the other methods
Dabman2392
Scratcher
100+ posts

Word counter

and sorry, i never checked the time this was posted.

Powered by DjangoBB