Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split() ? How to ignore Comma in between Inverted Comma's

Status
Not open for further replies.

apexbs

Technical User
Jun 2, 2002
42
0
0
CA
Hi;

I am using VB.NET 2003.

I am trying to importing data from text files and I am using split() function to get each substring in one row which is comma delimated and have inverted comma's for each subtring. It is working fine if there is no Comma in between inverted Commas. It gives me error if there is a Comma in the substring. Like for address we can have Comma. I don't know how to ignore the comma which is in between inverted commas. I can't change the delimeters b/c I am getting that files from client.

The sample of text row is

"123, John Street","Toronto","Ontario","M2M2M2"

Note: "123, John Street" is one substring.

Thanks.
 
Use the following code. Explanation is in the comments

Code:
Dim vals() As String
Dim unsplitString As String

'Initialize the string we want to parse
unsplitString = """CA"",""1234, Elk Grove"",""Ventura"""
'Remove Quotes from beginning and ending of string
unsplitString = unsplitString.Trim(""""c)
'Parse the string using (",") as the delimiter
vals = Split(unsplitString, """,""")

For Each s As String In vals
    MsgBox(s)
Next

stravis
 
Thanks, it worked for me. Actually, that line

Split(unsplitString, """,""")

work for me, I was using

Split(unsplitString, ",")

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top