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

  • Home
  • SEARCH
  • 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 993897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:29:43+00:00 2026-05-16T06:29:43+00:00

I’ve gotten a CSV file supposedly with seven columns, and I was doing just

  • 0

I’ve gotten a CSV file supposedly with seven columns, and I was doing just fine until recently, they started using commas inside the third data column, and also CR and LF characters, also inside the third column, all of this between double quotes.

I was reading it line by line, so I could cross-check it with another file, and point it to the right row in the other file, but now that they are including new line codes and also commas, my code is just messed up.

For example:

  1. 1,4778,"El murciélago estaba navegando",10/08/2010,906610,13496-86219-1,1. This one runs just fine.

  2. 1,4778,"El murciélago estaba navegando,
    y además estaba de parranda",10/08/2010,906610,13496-86219-1,1
    . Now this is bad.

Any way you suggest to solve this? The third data column is ALWAYS the one with these sudden changes. The others will never get to work with new lines or additional commas, so there is no need to filter those…

Thanks in advance!

  • 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-05-16T06:29:43+00:00Added an answer on May 16, 2026 at 6:29 am

    Probably the cleanest, most systematic way to handle it is to read character by character and use a small state machine, to deal with things like “we’re inside a quoted string, so ignore any comma, CR or LF”.

    One way to do this is to build an array where each row is a current state, and each column is a possible input character. You read an input character, and based on the current state and the input character, you get a next state to enter. You’ll typically also have a case statement to take actions based on the current state and the next state (e.g., append the current character to your CurrentField string when what you’ve read is allowed as part of a field), or save your current field string when you get to the end of the field.

    So, you start in the Start state. In the Start state, if you see a quote, you go to the QuotedField state. If you see a letter or digit, you go to the UnQuotedField state. If you see a comma, you go to the EndField state (i.e., you just read an empty field). If you see much of anything else, you go to the Error state.

    In the QuotedField state, anything but a quote is accepted and leaves you in the QuotedField state. When you do see a quote, you need to check whether the next character is a quote (a doubled quote translates to a quote mark embedded in the field) or something else (meaning the quote marked the end of the field). You can do that either by writing a bit of code by hand to peek at the next input character, and check if its a quote, or you can encode another state that goes back to the QuotedField state if it gets a quote, the EndField state if it finds a comma, or the Error state for almost anything else (e.g., a letter or digit).

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

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.