Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8465429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:02:41+00:00 2026-06-10T15:02:41+00:00

I have a CSV file I need to process which is a bit of

  • 0

I have a CSV file I need to process which is a bit of a nightmare. Esentially it is the following

"Id","Name","Description"
"1","Test1","Test description text"
"2","Test2","<doc><style>body{font-family:"Calibri","sans-serif";}</style><p class="test_class"
name="test_name">Lots of word xdoc content here.</p></doc>"
"guid-xxxx-xxxx-xxxx-xxxx","Test3","Test description text 3"

I’m using the File Helpers library to process the CSV rather than reinvent the wheel. However, due to the description field containing unescaped Word xdoc xml which contains quotes it’s getting rather confused when it comes to the start and end points of each record.

The following is an example mapping class.

[DelimitedRecord(","), IgnoreFirst(1), IgnoreEmptyLines()]
public class CSVDoc
{
    #region Properties
    [FieldQuoted('"', QuoteMode.AlwaysQuoted), FieldTrim(TrimMode.Both)]
    public string Id;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted), FieldTrim(TrimMode.Both)]
    public string Name;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted), FieldTrim(TrimMode.Both)]
    public string Description;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted), FieldTrim(TrimMode.Both)]
}

I considered (despite my hate of regex for this kind of task) replacing all " with ' and then using ((?<=(^|',))'|'(?=($|,'))) pattern to replace all ' with " at the start and end of lines and where they are formatted ','. However, the dirty file contains some lines which end with a " and some css style attributes which are formatted ","

So now I’m left scratching my head trying to figure out how to do this and how it can be automated.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:02:43+00:00Added an answer on June 10, 2026 at 3:02 pm

    You’re going to have to re-invent the wheel, because that’s not valid CSV or indeed a reasonable file at all – it doesn’t have any sort of provably consistent escaping rules (e.g. we don’t know if the plain-text columns are escaped correctly or not).

    Your best bet is to ask the person producing this to fix the bug, it should be e.g.:

    "2","Test2","<doc><style>body{font-family:""Calibri"",""sans-serif"";}</style><p class=""test_class""
    name=""test_name"">Lots of word xdoc content here.</p></doc>"
    

    Which your parser should handle fine, and which should not be hard for them to produce in a simple and efficient manner.

    Failing that, you’ll have to hand-code the parser to:

    1. Read a line.
    2. Check for unescaped ” (any "that isn’t followed by a " a , or whitespace.
    3. If none found, parse as CSV.
    4. If any found, parse as this horrible thing until you hit the line ending with “

    It may be easier to look for < if that is consistently not used in the other lines. Or perhaps for <doc if it consistently identifies the correct rows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file with data looking like (see below). I need help
I have a .csv file containing 3 columns of data. I need to create
I have a .csv file with chinese characters. I need to read in these
I have a very big CSV file (1GB+), it has 100,000 line. I need
Little Background: I have csv file which has lots of rows and each row
I have a CSV file supplied from a client which has to be parsed
I have a huge CSV file I would like to process using Hadoop MapReduce
I have csv file exported from access. (dates formatted to match mysql) I need
I have a csv file and i need to import it to a table
I have a 10GB CSV file which is essentially a huge square matrix. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.