Possible Duplicate:
Javascript code to parse CSV data
Javascript: Splitting a string by comma but ignoring commas in quotes
I have a comma separated string like this:
car,jeep,,"ute,van",suv,truck
I need to split it and add it to array as following entries:
car
jeep
ute,van
suv
truck
I am currently first splitting the string by " and then replace , with some other character in the parts that have , only in the middle but not at the either ends.
Also I check if the length of split array is greater than 1 because in case I get strings that don't have " at all, I want to skip the replacing , part.
Then finally I join the array using "" to get the end result.
Can someone suggest any better way and efficient way to do this possibly using regex?