Is there any way to convert a comma separated string into an array in Ruby? For instance, if I had a string like this:
"one,two,three,four"
How would I convert it into an array like this?
["one", "two", "three", "four"]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the
splitmethod to do it:If you want to ignore leading / trailing whitespace use:
If you want to parse multiple lines (i.e. a CSV file) into separate arrays: