ruby - Split string variable into an array -
just wondering how split string variable letter letter , make array
my word
variable randomly selected word array of words:
word = $file_arr[rand($file_arr.length)]
how split word individual letters , add them array?
example: if word pulls word "hello" $file_arr
how make array like: ["h", "e", "l", "l", "o"]
out of word
variable
all i've been able find online people doing strings type in , splitting on comma, how variable?
use string#chars
http://ruby-doc.org/core-2.0.0/string.html#method-i-chars
2.3.1 :009 > "hello world".chars => ["h", "e", "l", "l", "o", " ", "w", "o", "r", "l", "d"]
Comments
Post a Comment