I'm using the below code to split a line into an array but some of the elements contain commas like the example below.
Current code : output.Add(sr.ReadLine().Split(New Char() {","c}))
Every element has "" around it in the CSV and I can't change it as it is from a supplier. I'm splitting the line into an array then removing the " using this.
'data(iRow)(0) = data(iRow)(0).Replace(Chr(34), "")
I'm running into problems because the elements like my,park
that need to remain same.
Example Data : The data is read like this from the CSV/Text file
"my,park","mydate","my school","myhome"
My full function is below if that helps, been stuck on it for 2 days now.
Dim output As New ArrayList()
Using sr As StreamReader = New StreamReader(fileName)
While Not sr.EndOfStream
output.Add(sr.ReadLine().Split(New Char() {","c}))
End While
End Using
Return output
How can I complete this efficiently and get the correct output? The process is tripping up with the element containing commas and I don't know how to split on ","
Thanks in advance