Advanced Split Function for Data Import..

I was wondering what is a simple but fast way to extract data from a comma delimitad string.
A simple split will not work since certain fields have a String enclosed in a "" and the comma
within the string should not be used as a delimiter.

Below is a sample of a srting i would like to break down correctly

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I suggest you first parse your line to find the " character, and then replace the commas by another control char (such as ¤ or another one...) until the next ".

Then you can use the Split function, that seems to best fit your requirements here.

Afterwards you can even replace the ¤ by the original commas to retreive the string that was between ""

I hope this will help.
maybe look at these aswell

1. Connecting with OLEDB connection  string:

2. Connecting using INI file and OLEDB:

3. Description of ODBC .NET connection string format:
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Try this function:

Private Function Tokenize(putHereTheStringToReplace as String) As String()
        Dim testString As String = "PB/NB,CA, AS3EM,  EON INCLUDED BRONZE EVC 501-1000M,OPT-E-MAN,Y,""1J,3J"",K,,,U,L,, "
        Dim charArray() As Char
        Dim replaceComma As Boolean = False
        Dim index As Integer
        Dim splittedString() As String

        charArray = testString.ToCharArray()

        For index = 0 To charArray.GetUpperBound(0)
            If charArray(index) = ChrW(34) Then
                replaceComma = Not replaceComma
            ElseIf charArray(index) = ChrW(44) Then
                If replaceComma Then charArray(index) = ChrW(20)
            End If

        splittedString = New String(charArray).Split(ChrW(44))

        For index = 0 To splittedString.GetUpperBound(0)
            splittedString(index) = splittedString(index).Replace(ChrW(20), ChrW(44))

        return splittedString
    End Sub

Askme for anything if you want.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexPonnathAuthor Commented:
Hi Somas,

your script works great but i was wondering what the "putHereTheStringToReplace" stands for
since i dont see any reference in the function to that.
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Hey, it's SoMoS, not SoMaS, i'm a men ... :)

Replace the putHereTheStringToReplace with the testString in the function, its easy...c

Askme more if you need it

AlexPonnathAuthor Commented:
Sorry about the name SoMoS...

I thought so regarding the string, i just wasnt sure..

Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Ok, I'm waiting the points with open arms ... :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.