How to split single quoted comma delimited values containing commas in Ruby -
Say I have a straight, in which a quote from a comma contains delimited values, which can not be included in the comma in this way:
"Apple, Banana ',' lemon '" and I want to divide it into the array
[Obviously, if I type the' code ' code> ["apple", "banana", "lemon"] to me Can not understand the only way to do this Is
a = [] s = " 'apples, bananas,' 'Lemon' 's.scan (/ \' ([^ \ ']) \' /) {| I A & lt; & Lt; I [0]} # results ["apple, banana", "lemon"] But is there any more elegant way? Is there anything with split method that I do not get, which is causing strange results?
Actually divided the way it is supposed to work, but it seems that you have a comma Trying to split the values separated by. And already there is a solution in Ruby's studbubble for this:
Or if you want an external library (which is better, faster, ...) Want to