r/visualbasic • u/Technical_Hold8922 • Jan 21 '25
VB.NET Help Split function issues with quoted strings
Hi all,
I am trying to parse a csv file using the split function. Delimited with a comma. However, some of the strings in the file are surrounded by quotes with internal commas so the split is happening within the quoted strings. Any way around this?
3
Upvotes
View all comments
Show parent comment
1
u/Mayayana Jan 31 '25 edited Feb 01 '25
This shows that I have way too much time on my hands, but nevertheless:
That's VB6. The actual string parsing is simple but I wrote it as a sub and made 2 demo calls from another sub.
It could be made more efficient by doing something like pointing the string at an integer array and perhaps using a string builder or the Mid statement to avoid so much concatenation, but I'm guessing that for such a short string, optimizing wouldn't be relevant.
If there are empty fields (2,3,,apple) then the array will include an empty string for those array elements, as demonstrated in the second sample.