
-----------------------------------
Selfi
Tue May 25, 2004 2:10 pm

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?

-----------------------------------
LiquidDragon
Tue May 25, 2004 2:28 pm


-----------------------------------
really simple


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
Tue May 25, 2004 4:00 pm


-----------------------------------
What LiquidDragon did. 

To find the length of a word, you use the length() function.

E.g. 

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
Thu May 27, 2004 10:27 am


-----------------------------------
This saves variable space, by making the array as big as the word only, rather than 100:

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
Thu May 27, 2004 4:15 pm


-----------------------------------
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
Thu May 12, 2005 4:31 pm


-----------------------------------
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
Thu May 12, 2005 4:34 pm


-----------------------------------
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
Thu May 12, 2005 5:21 pm


-----------------------------------
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 :P)
In any case, this question was just asked.  [url=http://www.compsci.ca/v2/viewtopic.php?t=8766]Click!

-----------------------------------
Neo
Thu May 12, 2005 8:57 pm


-----------------------------------
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
Thu May 12, 2005 9:56 pm


-----------------------------------
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

-----------------------------------
Bacchus
Thu May 12, 2005 9:59 pm


-----------------------------------
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
Sat May 14, 2005 6:25 am


-----------------------------------
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
Sat May 14, 2005 3:25 pm


-----------------------------------
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
Sat May 14, 2005 4:01 pm


-----------------------------------
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
Sat May 14, 2005 4:47 pm


-----------------------------------
Yep, I like your string manipulation tut, helped me with a lot of dwite questions  :) Thanks a lot

- Mystic

-----------------------------------
sockoo
Sun May 15, 2005 3:18 pm


-----------------------------------
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 :P , 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 :P )
