Parsing a comma delimited file that has comma embedded within double quotes

Venkat Venkataramanan 76 Reputation points
2020-11-25T17:15:54.137+00:00

Hello:

I am working with a Integration Project in MS VS 2019.

I have a comma-delimited flat file. One of the fields is double-quoted and may have a comma inside it. When the file gets parsed, it gets thrown of by the embedded comma,

For example, one of the lines in the flat file is:

ID, ShoppingList, Amount
9999,"The shopping list includes men's shoes, jackets and helmets", 325

The flat file extracts:
ID: 9999
ShoppingList: "The Shopping list includes men's shoes
Amount: jackets and Helments"

I would like to see the values below:
ID: 9999
ShoppingList: The shopping list includes men's shoes, jackets and helmets
Amount: 325

Please note the double-quotes has been stripped off Shopping list. This is a lesser issue; I can create a calculated field that strips the double-quotes off the value parsed.

But the bigger issyes is that the embedded commas are messing up the parsing.

Thank You.

Venki

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,309 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,619 questions
{count} votes

Accepted answer
  1. Castorix31 86,406 Reputation points
    2020-11-25T18:01:51.31+00:00

    You can use TextFieldParser.HasFieldsEnclosedInQuotes = true;
    I tested with your sample and I get the 3 fields
    9999
    The shopping list includes men's shoes, jackets and helmets
    325

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Venkat Venkataramanan 76 Reputation points
    2020-11-25T18:32:50.733+00:00

    Castorix31:

    Yes I learned new. The answer was as simple as setting the Text Qualifier to be a double-quotes. It works like a charm.

    venki

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.