From: Zipizap zipizap Date: 2011-09-11T23:58:45+09:00 Subject: Re: making an array of strings Joe Collins wrote in post #1021260: > I want to make an array of strings, i.e boy, girl, cat dog > how do I do that in Ruby? > #You can do it several ways: # A- Create an array which elements are strings str_arr = ["boy", "girl", "cat", "dog"] # => ["boy", "girl", "cat", "dog"] # B- The same using %w - it splits a string into words, and returns an array. Notice also that () is used to delimit the string, instead of "" str_arr = %w(boy girl cat dog) # => ["boy", "girl", "cat", "dog"] > Also, I want to read words from a file and make them an array of > strings. I can read files fine but making an array of strings is where I > am > stumped. #To decompose a string into words, and store them in an array, you can use String#split [1] - it fits like a glove Also, if you want to refresh these details, have a reading over "The Pragmatic Programmer's Guide" which is available online, and very well explained [2] Cheers [1] http://ruby-doc.org/core/classes/String.html#M001165 [2] http://www.rubycentral.com/pickaxe/ > > Thanks in advance > > Joe -- Posted via http://www.ruby-forum.com/.