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

PB/NB,CA, AS3EM,  EON INCLUDED BRONZE EVC 501-1000M,OPT-E-MAN,Y,"1J,3J",K,,,U,L,,
AlexPonnathAsked:
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.

GlomCommented:
Hi,

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.
0
RonaldBiemansCommented:
maybe look at these aswell

1. Connecting with OLEDB connection  string:
http://www.dotnet247.com/247reference/msgs/23/119232.aspx

2. Connecting using INI file and OLEDB:
http://www.aspalliance.com/ericm/articles/textdb.asp

3. Description of ODBC .NET connection string format:
http://www.c-sharpcorner.com/Code/2002/Sept/ODBCDataProvider1.asp
0
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
        Next

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

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

        return splittedString
    End Sub

Askme for anything if you want.

SoMoS
0

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.
0
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

SoMoS
0
AlexPonnathAuthor Commented:
Sorry about the name SoMoS...

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

Alex
0
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Ok, I'm waiting the points with open arms ... :)
0
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.