I have string: @address = \"10 Madison Avenue, New York, NY - (212) 538-1884\"
What\'s the best way to split it like this?
10 Madison Avenu
String#split has a second argument, the maximum number of fields returned in the result array: http://ruby-doc.org/core/classes/String.html#M001165
@address.split(",", 2)
will return an array with two strings, split at the first occurrence of ",".
the rest of it is simply building the string using interpolation or if you want to have it more generic, a combination of Array#map
and #join
for example
@address.split(",", 2).map {|split| "#{split}
" }.join("\n")