title: How to export a field that contain a comma into a CSV file in C sharp code
body: <p>My question is about CSV file in C#. If a field contains a comma how can this be exported  into a CSV file as a one field? See <code>Field 2</code> in the sample below:</p>
  <blockquote>
  <p>Field1|Field2|Field3</p>
  <p>10.20|Doe,John|Box No 1</p>
  </blockquote>
  <p>I have this code:</p>
  <pre><code>//Get indices
  indices = DenormalizeIndices(id);
  foreach (DataRow row in indices.Tables[0].Rows)
  {
   line = null;
    //We're only going to use selected fields
   for (i = 0; i &lt; 3; i++)
   {
    if (line != null)
      line += DELIMITER;
    //Figure out the mapped field name we have defined
    if (i &gt;= INDICES_TO_INCLUDE.Length)
      line += &quot;&quot;; //Nothing to populate
    else
    if (String.IsNullOrEmpty(INDICES_TO_INCLUDE[i]))
      line += &quot;&quot;;
    else
      line += &quot;=\&quot;&quot; + row[INDICES_TO_INCLUDE[i]].ToString() + &quot;\&quot;&quot;;
  </code></pre>
  <p>But with this code above the CSV file result will be as below, it will separate the index value of <code>Field2</code>:</p>
  <p>Field1 |  Field2  | Field3   |   Field4</p>
  <p>10.20  |  Doe     |   John   |   Box No 1</p>
  <p>What else should I add to the code so the result will be as below on <code>Field2</code>?</p>
  <blockquote>
  <p>Field2</p>
  <p>Doe, John</p>
  </blockquote>