Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>CSV formatting has some gotchas. Have you asked yourself these questions:</p> <ul> <li>Does any of my data have embedded commas?</li> <li>Does any of my data have embedded double-quotes?</li> <li>Does any of my data have have newlines?</li> <li>Do I need to support Unicode strings?</li> </ul> <p>I see several problems in your code above. The comma thing first of all... you are stripping commas:</p> <pre><code>CsvLine.Append(Format(b.Price, "c").Replace(",", "")) </code></pre> <p>Why? In CSV, you should be surrounding anything which has commas with quotes:</p> <pre><code>CsvLine.Append(String.Format("\"{0:c}\"", b.Price)) </code></pre> <p>(or something like that... my VB is not very good). If you're not sure if there are commas, but put quotes around it. If there are quotes in the string, you need to escape them by doubling them. <code>"</code> becomes <code>""</code>.</p> <pre><code>b.Title.Replace("\"", "\"\"") </code></pre> <p>Then surround this by quotes if you want. If there are newlines in your string, you need to surround the string with quotes... yes, literal newlines <em>are</em> allowed in CSV files. It looks weird to humans, but it's all good.</p> <p>A good CSV writer requires some thought. A good CSV reader (parser) is just plain hard (and no, regex not good enough for parsing CSV... it will only get you about 95% of the way there).</p> <p>And then there is Unicode... or more generally I18N (Internationalization) issues. For example, you are stripping commas out of a formatted price. But that's assuming the price is formatted as you expect it in the US. In France, the number formatting is reversed (periods used instead of commas, and <em>vice versa</em>). Bottom line, use culture-agnostic formatting wherever possible.</p> <p>While the issue here is <em>generating</em> CSV, inevitably you will need to parse CSV. In .NET, the best parser I have found (for free) is <a href="http://www.codeproject.com/KB/database/CsvReader.aspx" rel="noreferrer">Fast CSV Reader</a> on <a href="http://www.codeproject.com" rel="noreferrer">CodeProject</a>. I've actually used it in production code and it is really really fast, and very easy to use!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload