December 2017
Intermediate to advanced
860 pages
16h 1m
English
We can split the value of a string into an array of variables using the split function. Let's have 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 string "mastering,metasploit" now forms 0th and the 1st element of the array b, containing the values "mastering" and "metasploit" respectively.
Read now
Unlock full access