I’m adding a function to my own personal toolkit lib to do simple CSV to HTML table conversion.
I would like the smallest possible piece of code to do this in C#, and it needs to be able to handle CSV files in excess of ~500mb.
So far my two contenders are
-
splitting csv into arrays by
delimiters and building HTML output -
search-replace delimiters with table
th tr td tags
Assume that the file/read/disk operations are already handled… i.e., i’m passing a string containing the contents of said CSV into this function. The output will consist of straight up simple HTML style-free markup, and yes the data may have stray commas and breaks therein.
update: some folks asked. 100% of the CSV i deal with comes straight out of excel if that helps.
Example string:
a1,b1,c1\r\n a2,b2,c2\r\n
Read All Lines into Memory
or Read one line at a time
… @Jimmy … I created an extended version using LINQ. Here is the highlight … (lazy eval for line reading)