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 188175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:57:32+00:00 2026-05-11T15:57:32+00:00

I am looking for suggestions on how to handle a csv file that is

  • 0

I am looking for suggestions on how to handle a csv file that is being created, then uploaded by our customers, and that may have a comma in a value, like a company name.

Some of the ideas we are looking at are: quoted Identifiers (value ‘,’ values ‘,’etc) or using a | instead of a comma. The biggest problem is that we have to make it easy, or the customer won’t do it.

  • 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. 2026-05-11T15:57:33+00:00Added an answer on May 11, 2026 at 3:57 pm

    As others have said, you need to escape values that include quotes. Here’s a little CSV reader in C♯ that supports quoted values, including embedded quotes and carriage returns.

    By the way, this is unit-tested code. I’m posting it now because this question seems to come up a lot and others may not want an entire library when simple CSV support will do.

    You can use it as follows:

    using System; public class test {     public static void Main()     {         using ( CsvReader reader = new CsvReader( 'data.csv' ) )         {             foreach( string[] values in reader.RowEnumerator )             {                 Console.WriteLine( 'Row {0} has {1} values.', reader.RowIndex, values.Length );             }         }         Console.ReadLine();     } } 

    Here are the classes. Note that you can use the Csv.Escape function to write valid CSV as well.

    using System.IO; using System.Text.RegularExpressions;  public sealed class CsvReader : System.IDisposable {     public CsvReader( string fileName ) : this( new FileStream( fileName, FileMode.Open, FileAccess.Read ) )     {     }      public CsvReader( Stream stream )     {         __reader = new StreamReader( stream );     }      public System.Collections.IEnumerable RowEnumerator     {         get {             if ( null == __reader )                 throw new System.ApplicationException( 'I can't start reading without CSV input.' );              __rowno = 0;             string sLine;             string sNextLine;              while ( null != ( sLine = __reader.ReadLine() ) )             {                 while ( rexRunOnLine.IsMatch( sLine ) && null != ( sNextLine = __reader.ReadLine() ) )                     sLine += '\n' + sNextLine;                  __rowno++;                 string[] values = rexCsvSplitter.Split( sLine );                  for ( int i = 0; i < values.Length; i++ )                     values[i] = Csv.Unescape( values[i] );                  yield return values;             }              __reader.Close();         }     }      public long RowIndex { get { return __rowno; } }      public void Dispose()     {         if ( null != __reader ) __reader.Dispose();     }      //============================================       private long __rowno = 0;     private TextReader __reader;     private static Regex rexCsvSplitter = new Regex( @',(?=(?:[^'']*''[^'']*'')*(?![^'']*''))' );     private static Regex rexRunOnLine = new Regex( @'^[^'']*(?:''[^'']*''[^'']*)*''[^'']*$' ); }  public static class Csv {     public static string Escape( string s )     {         if ( s.Contains( QUOTE ) )             s = s.Replace( QUOTE, ESCAPED_QUOTE );          if ( s.IndexOfAny( CHARACTERS_THAT_MUST_BE_QUOTED ) > -1 )             s = QUOTE + s + QUOTE;          return s;     }      public static string Unescape( string s )     {         if ( s.StartsWith( QUOTE ) && s.EndsWith( QUOTE ) )         {             s = s.Substring( 1, s.Length - 2 );              if ( s.Contains( ESCAPED_QUOTE ) )                 s = s.Replace( ESCAPED_QUOTE, QUOTE );         }          return s;     }       private const string QUOTE = '\'';     private const string ESCAPED_QUOTE = '\'\'';     private static char[] CHARACTERS_THAT_MUST_BE_QUOTED = { ',', ''', '\n' }; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking for suggestions on file system management tools. We have several terabytes of images,
I'm looking for suggestions on new development system from some programmers that have more
I'm looking for suggestions on possible IPC mechanisms that I can implement in my
I'm looking for suggestions as well as any benchmarks or observations people have. We
Hi I'm looking for suggestions on how best to handle the submission of a
I'm looking for suggestions, or really good tutorials on how to handle passing ids
What I am looking to accomplish is a filter (or similar) that would handle
I am looking for suggestions to properly handle separate debug and release build subdirectories,
I have a set of functions that handle the db connection. I want to
I'm looking for suggestions on Flash realtime servers. Currently, we use a combination of

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.