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]
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.
My answer would change depending on some variables like how big your
file is
and whether the words are each on their own line or if there is one line
with spaces between each, or if there are lots of lines with lots of
words
one each, so might be beneficial to provide more information.