Computer Science Canada

Help?? How to make Turing search for a given word??

Author:  cohen_ohyea [ Wed Jan 07, 2004 8:35 pm ]
Post subject:  Help?? How to make Turing search for a given word??

I have to do a project where the user must enter a sentence or series of sentences and then asks them to search for a word in the sentence or sentences. Then displays the sentence with how many times the word they searched for appears. I need serious help Crying or Very sad Any Ideas?????

Author:  AsianSensation [ Wed Jan 07, 2004 10:48 pm ]
Post subject: 

use the index function, cut the part of the string you already searched, and then index again. Then index some more until you run out of stuff to index with.


break the sentence into individual words, store all the values in an array and then search like that.

Author:  DanShadow [ Fri Jan 09, 2004 3:11 pm ]
Post subject: 

Yeah, go for an array. Store each word in an array, then cross check in a for loop (1.. length of array), the have a counter that adds up by 1 when it finds the word its looking for.

var words : array 1 .. 30 of string
locate (2, 1)
put "Enter a sentence or two: " ..
for i : 1 .. 30
    locate (1, 1)
    put 30 - i, " words left."
    get words (i)
end for
var counter : int := 0
var txt : string := ""
put "What word do you wish to search for: " ..
get txt
for i : 1 .. 30
    if txt = words (i) then
        counter := counter + 1
    end if
end for
put "The word ", txt, " was typed ", counter, " times in the sentence(s)."
put ""
for i : 1 .. 30
    put words (i), " " ..
end for

Yeah I know its messy, but thats how its done.

Author:  McKenzie [ Fri Jan 09, 2004 3:52 pm ]
Post subject: 

Listen to AZN,
Index is the way to go, watch out for the problem of finding words within words. e.g.
"I went to the store"
does not have the word "we" in it, but index will tell you it does.

Author:  DanShadow [ Fri Jan 09, 2004 7:19 pm ]
Post subject: 

Yeah, you probably should listen to Asian Sensation...he is the genius in these matters. I just havent ever worked with Index...Ill have to do that.

Author:  Andy [ Fri Jan 09, 2004 7:32 pm ]
Post subject: 

dan shadow... dont call ur self the array master juss cuz you dont know about linked lists... but then again its turing...

Author:  DanShadow [ Fri Jan 09, 2004 7:59 pm ]
Post subject: 

No, no, not really the master of the Array...just the master of the rare and forbidden Demon Array....nah. I just couldnt think of anything to go after Demon I just put Master.... 8)

Author:  Andy [ Fri Jan 09, 2004 8:01 pm ]
Post subject: 

well learn about linked lists any ways...

Author:  DanShadow [ Fri Jan 09, 2004 8:17 pm ]
Post subject: 

Ok Dodge, I will...but where should I look, Tutorials or something? The Turing Help file doesnt inc lude linked lists...

Author:  Andy [ Fri Jan 09, 2004 8:35 pm ]
Post subject: 

i'll write a tutorial one of these days, but y not ask the new turing mod?

Author:  McKenzie [ Fri Jan 09, 2004 8:42 pm ]
Post subject: 

Don't worry Dan, Dodge just feels that you're stealing his schtick. Dodge his earned he Whatdotcolour warrior title, but he doesn't see any proof that you've earned yours.
As for advanced topics that people mention to make you feel small (and that was the only reason Dodge brought it up (be honest Dodge)). Use the Search feature provided in this site. If you find nothing try google. With google you will almost always get C/C++ help however (often if you read into it you will still glean the basic ideas)

Author:  Andy [ Fri Jan 09, 2004 9:14 pm ]
Post subject: 

ok fine... mckenzie is rite, i was just being mean... dont take the stuff i say too seriously unless whatdotcolor is in it and noob is not used in the same sentence.

Author:  cohen_ohyea [ Sun Jan 11, 2004 1:03 pm ]
Post subject: 

You guys have been very helpful but I am still kind of vauge of how the index function is used. Embarassed