I have data from a CSV file that’s already loaded into memory. So I might have something like this:
csv_string = 'Value 1,Value 2,"Hey, it\'s value 3!",Value 4 has "some quotes"'
Obviously I won’t want to do csv_string.split(","). Since it seems like splitting a CSV-style string this way might be a not-all-that-uncommon need, I was wondering if there’s a solution already out there.
For parsing CSV, Ruby comes with the
csvlibrary:Unfortunately, your string doesn’t actually contain valid CSV, so what you’ll really get is the following exception:
Since your data doesn’t actually conform to any common standard, there can obviously not be a common parser and you’ll have to write your own.
Alternatively, you could change your data to be valid CSV, for example like this: