title: escaping tricky string to CSV format
body: <p>I have to create a CSV file from webservice output and the CSV file uses quoted strings with comma separator. <strong>I cannot change the format</strong>...</p>
  
  <p>So if I have a <code>string</code> it becomes a <code>"string"</code>...
  If the value has quotes already they are replaced with double quotes.
  For example a <code>str"ing</code> becomes <code>"str""ing"</code>...</p>
  
  <p>However, lately my import has been failing because of the following</p>
  
  <ul>
  <li>original input string is: <code>"","word1,word2,..."</code></li>
  <li>every single quote is replaced by double resulting in: <code>"""",""word1,word2,...""</code></li>
  <li>then its prefixed and suffixed with quote before written to CVS file:  <code>""""",""word1,word2,..."""</code></li>
  </ul>
  
  <p>As you can see the final result is this:</p>
  
  <pre><code>""""",""word1,word2,..."""
  </code></pre>
  
  <p>which breaks my import (is sees it as another field)...
  I think the issue is appereance of <code>","</code> in the original input string.</p>
  
  <p>Is there a CVS escape sequence for this scenario? </p>
  
  <h2>Update</h2>
  
  <p>The reason why above breaks is due to BCP mapping file (BCP utility is used to load CSV file into SQL db) which has terminator defined as <code>&amp;quot;,&amp;quot;</code> . So instead of seeing 1 field it sees 2...But I cannot change the mapping file...</p>