Computer Science Canada

counting letters

Author:  Selfi [ Tue May 25, 2004 2:10 pm ]
Post subject:  counting letters

ive thougth about this a bit, and i cant seem to figure out how to do it. i've been trying to count the number of letters in a word and then put each individual letter into an array, but im not sure how to go about it. any ideas?

Author:  LiquidDragon [ Tue May 25, 2004 2:28 pm ]
Post subject: 

really simple

code:

var word : string
var letter : array 1 .. 100 of string %variable to store letters

get word %getting the word

for i : 1 .. length (word)
    letter (i) := word (i) %assigning each value to the letter position
end for

for i : 1 .. length (word)
    put letter (i) %displaying on screen
end for


It's kind of commented. I'm not the great at commenting but you can survive.

Author:  guruguru [ Tue May 25, 2004 4:00 pm ]
Post subject: 

What LiquidDragon did.

To find the length of a word, you use the length() function.

E.g.
code:

length("hello") = 5
length("goodbyePerson") = 13

var word : string := "myNewWord"
length (word) := 9


Then getting each letter of the word is what the above poster did.

Author:  beard0 [ Thu May 27, 2004 10:27 am ]
Post subject: 

This saves variable space, by making the array as big as the word only, rather than 100:
code:

var word : string
get word %getting the word
var letter : array 1 .. length(word) of string %variable to store letters
for i : 1 .. length (word)
    letter (i) := word (i) %assigning each value to the letter position
end for

for i : 1 .. length (word)
    put letter (i) %displaying on screen
end for

Author:  guruguru [ Thu May 27, 2004 4:15 pm ]
Post subject: 

Tsk tsk... that is bad programming practive. You should never declare a variable anytime other than the beggining of the program. For this, you could use a flexible array. Or a function that creates a local variable and returns the filled array as the result.

Author:  parasite [ Thu May 12, 2005 4:31 pm ]
Post subject: 

now could you replace letters with words .. so that it counts how many words are in a sentance/line ..I'm new at turing and this site so your help would be appreciated

i realize NOW two seconds after i posted this that this was posted about a year ago..sorry bout that .. but my problem still stands so if you could help that would be great

Author:  Neo [ Thu May 12, 2005 4:34 pm ]
Post subject: 

parasite wrote:
now could you replace letters with words .. so that it counts how many words are in a sentance/line ..I'm new at turing and this site so your help would be appreciated


Simply count the number of spaces between the words.

Author:  Cervantes [ Thu May 12, 2005 5:21 pm ]
Post subject: 

Nope. Try a one sentance example:
Hello everyone.
One space, two words.
Or, try a multi sentance example in which the person puts two spaces after their periods. You'll get too many words. (I can't really put an example of this because if I have two spaces in a row, Dan's dealie filters it down to just one Razz)
In any case, this question was just asked. Click!

Author:  Neo [ Thu May 12, 2005 8:57 pm ]
Post subject: 

Count the numbers between the words and add 1.
I know its proper format to use two spaces after a period but who does it anyways?

Author:  parasite [ Thu May 12, 2005 9:56 pm ]
Post subject: 

put "Thanks so much"
i was looking all over the forums for a tutorial or topic like this.. turns out it was right under my mouse Wink this will help me with my class work a lot ..thanks again

Author:  Bacchus [ Thu May 12, 2005 9:59 pm ]
Post subject: 

Neo wrote:
I know its proper format to use two spaces after a period but who does it anyways?
it is? maybe thats y i always suked at grammar and spelling and such lol

Author:  Cervantes [ Sat May 14, 2005 6:25 am ]
Post subject: 

Neo wrote:
I know its proper format to use two spaces after a period but who does it anyways?

I do.
The program needs to work regardless of how the user chooses to type his sentances.

Author:  sockoo [ Sat May 14, 2005 3:25 pm ]
Post subject: 

i think i know what ur looking for .. just easily put

get sentence : * % gets the whole sentence to the end
put sentence(length)

this will .. output how many charcs are in ur sentence plus the spaces .. if u dont want the spaces included .. run an if statement to find how many spaces .. use the index funktion to find spaces and then just substract it from the number of charc in the sentence

Author:  Cervantes [ Sat May 14, 2005 4:01 pm ]
Post subject: 

Heh, that would take care of the first part of the first question, posed about a year ago. The current topic of this thread is to answer parasite's question: how to count the number of words, not letters.

Author:  MysticVegeta [ Sat May 14, 2005 4:47 pm ]
Post subject: 

Yep, I like your string manipulation tut, helped me with a lot of dwite questions Smile Thanks a lot

- Mystic

Author:  sockoo [ Sun May 15, 2005 3:18 pm ]
Post subject: 

Cervantes wrote:
Heh, that would take care of the first part of the first question, posed about a year ago. The current topic of this thread is to answer parasite's question: how to count the number of words, not letters.


doh sorry , tried to be usful Razz , to find the amount of words would you not just find the space using either index function or if statements then once you find out where ur spaces are .. its pretty much ez to find the word amount ?

(im new with string minipulation .. trying to get the just of it .. , plz ignore my noobness Razz )


: