Author |
Message |
Selfi
|
Posted: 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? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
LiquidDragon
|
Posted: Tue May 25, 2004 2:28 pm Post subject: (No 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. |
|
|
|
|
|
guruguru
|
Posted: Tue May 25, 2004 4:00 pm Post subject: (No 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. |
|
|
|
|
|
beard0
|
Posted: Thu May 27, 2004 10:27 am Post subject: (No 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
|
|
|
|
|
|
|
guruguru
|
Posted: Thu May 27, 2004 4:15 pm Post subject: (No 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. |
|
|
|
|
|
parasite
|
Posted: Thu May 12, 2005 4:31 pm Post subject: (No 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 |
|
|
|
|
|
Neo
|
Posted: Thu May 12, 2005 4:34 pm Post subject: (No 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. |
|
|
|
|
|
Cervantes
|
Posted: Thu May 12, 2005 5:21 pm Post subject: (No 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 )
In any case, this question was just asked. Click! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Neo
|
Posted: Thu May 12, 2005 8:57 pm Post subject: (No 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? |
|
|
|
|
|
parasite
|
Posted: Thu May 12, 2005 9:56 pm Post subject: (No 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 this will help me with my class work a lot ..thanks again |
|
|
|
|
|
Bacchus
|
Posted: Thu May 12, 2005 9:59 pm Post subject: (No 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 |
|
|
|
|
|
Cervantes
|
Posted: Sat May 14, 2005 6:25 am Post subject: (No 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. |
|
|
|
|
|
sockoo
|
Posted: Sat May 14, 2005 3:25 pm Post subject: (No 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 |
|
|
|
|
|
Cervantes
|
Posted: Sat May 14, 2005 4:01 pm Post subject: (No 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. |
|
|
|
|
|
MysticVegeta
|
Posted: Sat May 14, 2005 4:47 pm Post subject: (No subject) |
|
|
Yep, I like your string manipulation tut, helped me with a lot of dwite questions Thanks a lot
- Mystic |
|
|
|
|
|
|