It might be very simple but I can't find the solution.
I try to import a csv file via textreader and I like to split the line.
The values are between double quotes and separated with ';'
Example:
"Company1";"Product2";"Country3";"Turnover4"
Using Regex.Split(";", line) gives
"Company1"
"Product2"
"Country3"
"Turnover4"
I want however the following:
Company1
Product2
Country3
Turnover4
You could use a replace of quote to empty string and the split on ;.
The main problem arises when you have a ; within the quotes. It would be smarter to replace ";" by || (for example) and then replace all quotes left by an empty string (to get rid of the first and last quote per line). After that you do a split on || and you have a better result.
If you want to use Regex you could do something like this:
B4X:
Dim Values As List
Dim Buffer As String
Values.Initialize
Line = QUOTE & "Company1" & QUOTE & ";" & QUOTE & "Product2" & QUOTE 'This is just a sample.
Values = Regex.Split(";", Line)
For I = 0 To Values.Size - 1
Buffer = Values.Get(I)
Buffer = Buffer.Replace(QUOTE, "")
Msgbox(Buffer, "")
Next
@ NJDude
Buffer = Buffer.Replace(QUOTE, "") did the job.
Thank you so much!!
@ COBRASoft
I might need you suggestions as well since for some rows I get an index out of bound error. Some article descriptions contains ';'
I like to thank you as well!
That is exactly what I want to do. But I have to load the CSV first to import it in the SQLite database. This loading of a large csv file for import doesn't work with StringUtils.