----------------------------------- cohen_ohyea Sun Jan 11, 2004 3:59 pm An array that stores each word of a sentence as its own var. ----------------------------------- Can some one help me with code that gets a sentence from the user and stores each words as its own variable?? The code has to work with a sentence 1 word long or 100 words long depending on what the user inputs as there sentence. Ur help is much appreciated. :D ----------------------------------- Tony Sun Jan 11, 2004 5:19 pm ----------------------------------- use substrings and index() to break the sentance up into words, then store them in a dynamic array. var sentance:string var num:int put "enter sentance" get sentance num:= index(" ", sentance) %index arguments might be in wrong order put sentance(1..num) this should isolate the first word of the sentance... :think: I think ----------------------------------- McKenzie Sun Jan 11, 2004 5:28 pm ----------------------------------- var sent:string var spot:int var words:array 1.. 1000 of string var numWord :int put "What you got?" get sent:* sent := sent + " " loop spot:= index(sent," ") exit when spot = 1 words(numWord) := sent(1..spot - 1) numWord := numWord +1 sent := sent(spot+1..*) end loop Sorry, I'd prefer to explain the problem, but I gotta go ----------------------------------- cohen_ohyea Sun Jan 11, 2004 8:10 pm ----------------------------------- thank you guys for your help but i dont think that is gonna work. The program I am working on has to get a sentence from the user and then the user has to be able to search for a word in the sentence they inputted and the program should display how many times the word they searched for appears. When i use the index command with your program it doesnt quite work out. any ideas. ----------------------------------- Andy Sun Jan 11, 2004 8:38 pm ----------------------------------- wow why didnt u tell us earlier? var sentence, word : string put "Enter Sentence" get sentence : * put "Enter Word" get word : * var count := 0 loop exit when index (sentence, word) = 0 count += 1 sentence := sentence (index (sentence, word) + length (word) .. *) end loop put "the word ", word, " appeared ", count, " times" ----------------------------------- cohen_ohyea Sun Jan 11, 2004 8:45 pm ----------------------------------- dodge_tomahawk you are the best!!! :D :D :D thanks soo much ive been working really hard on my program for school but so far it does nothing but looks pretty. now i can finish it :D ----------------------------------- Andy Sun Jan 11, 2004 8:54 pm ----------------------------------- u noe when u ask for help, you're supposed to tell us what u want to achieve, what ur thinking of doing, then some code to prove to us that you actually tried something so we can help more efficiently.. u dont want a whatdotcolor method for that do u? ----------------------------------- CITC Sun Jan 11, 2004 9:01 pm ----------------------------------- jeeze I would want a whatdotcolour method for that!! that would be so cool!! ----------------------------------- Andy Sun Jan 11, 2004 9:05 pm ----------------------------------- will start tomorrow ----------------------------------- cohen_ohyea Sun Jan 11, 2004 9:10 pm ----------------------------------- sorry. how would i alter your code so that it isnt case sensitive, checks "Word" along with "word" or "WORD. :? ----------------------------------- McKenzie Sun Jan 11, 2004 9:43 pm ----------------------------------- Dodge, the obvious answer is to load a 2D array with the colours of the word you are looking for then scan across the sentence one character at a time (it's a monospaced font so it's not to bad) You do have to consider multiline answers however. If you're going to use whatdotcolour, why be obvious? The cadillac solution is the to take a picture of the word then use picXor (you all read my picXor tut right???) With the picXor if the word matched all pixels would be white, if it didn't you could undo it buy XORing it again :D As far as upper/lower problems you have 2 answers 1. Use C, it strupr works great 2. make your own toUpper function. 1. make an empty "" string variable to build up your answer 2. check letter by letter through the word (for loop) if it is lower case add on it's uppercase version (it was an ascii value 32 lower like ans := ans + chr(ord(word(i)+32))) 3. result the answer 4. When you call the index function pass both the word and the sentence to your toupper function like: index(toupper(sentence),toupper(word)) ----------------------------------- Andy Mon Jan 12, 2004 11:53 am ----------------------------------- well i got the whatdotcolor solution... var sentence, word : string put "Enter Sentence" get sentence : * put "Enter Word" get word fcn whatdotcolorWordsearch (sentence, word : string) : int View.Set ("offscreenonly") var picID, count : int count := 0 picID := Pic.New (1, 1, length (sentence), 1) for i : 1 .. length (sentence) drawdot (i, 1, ord (sentence (i))) end for for i : 1 .. length (sentence) - length (word) + 1 for j : 1 .. length (word) if ord (word (j)) not= whatdotcolor (i + j - 1, 1) then exit elsif j = length (word) then count += 1 end if end for end for Pic.Draw (picID, 1, 1, picCopy) View.Set ("nooffscreenonly") result count end whatdotcolorWordsearch put whatdotcolorWordsearch (sentence, word) ----------------------------------- McKenzie Mon Jan 12, 2004 3:20 pm ----------------------------------- Good job Dodge, you have proven that whatdotcolour is the best function ever :lol: ----------------------------------- Andy Mon Jan 12, 2004 8:07 pm ----------------------------------- exactly.. so all u kids who think u're all that with ur string manipulation... forget everything u've ever learned and change to whatdotcolor... p.s. i will offer classes on whatdotcolor for 5 bux donation/2 hr to massey robotics team