上QQ阅读APP看书,第一时间看更新
The split function
We can split the value of a string into an array of variables using the split function. Let's have a look at a quick example that demonstrates this:
irb(main):001:0> a = "mastering,metasploit" => "mastering,metasploit" irb(main):002:0> b = a.split(",") => ["mastering", "metasploit"] irb(main):003:0> b[0] => "mastering" irb(main):004:0> b[1] => "metasploit"
We can see that we have split the value of a string from the "," position into a new array, b. The "mastering,metasploit" string now forms the 0th and 1st element of the array, b, containing the values "mastering" and "metasploit", respectively.