From: Todd Benson Date: 2008-02-21T04:30:15+09:00 Subject: Re: displaying user inputed arrays On Feb 17, 2008 9:18 AM, Isaac Toothyxdip wrote: > [code] > > puts "Ok now enter in 5 words, just be sure there are spaces inbetween > them" > > i = 0 > while i < 5 > words_group = gets["","","","",""] > print "#{words_group[i]}" > i =+ 1 > end > > [/code] > > What im trying to do is ask the user to input some words and display > them using arrays (learning program) i know you could do this easy other > ways but im trying to do it with arrays. What needs to be changed? > > THanks in advance It depends if you _must_ have 5 words entered or if you just want the first 5 words. In either case, look at the many available methods split, compact, scan. Also... ((gets.scan /w'*/) - [""])[0..4] This simply takes all the words typed on a line (a space is a word), deletes the spaces from the array, and takes the first five. I like this better than the gets.chomp.split way because with gets.chomp.split you will get punctuation (unless that is not important to you). With the other way, for example... words = "hi there, how are you? i'm fine, thanks." words.chomp.split(" ") => ["hi", "there,", "how", "are", "you?"] Note, the inclusion there of the comma and question mark. Technically, I would think "you?" is not a word. Depends on what you want to do. Todd