Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
class Program
|
||||
{
|
||||
private static string ConvertCsvToHtmlTable(string csvText)
|
||||
{
|
||||
//split the CSV, assume no commas or line breaks in text
|
||||
List<List<string>> splitString = new List<List<string>>();
|
||||
List<string> lineSplit = csvText.Split('\n').ToList();
|
||||
foreach (string line in lineSplit)
|
||||
{
|
||||
splitString.Add(line.Split(',').ToList());
|
||||
}
|
||||
|
||||
//encode text safely, and create table
|
||||
string tableResult = "<table>";
|
||||
foreach(List<string> splitLine in splitString)
|
||||
{
|
||||
tableResult += "<tr>";
|
||||
foreach(string splitText in splitLine)
|
||||
{
|
||||
tableResult += "<td>" + WebUtility.HtmlEncode(splitText) + "</td>";
|
||||
}
|
||||
tableResult += "</tr>";
|
||||
}
|
||||
tableResult += "</table>";
|
||||
return tableResult;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
<table><tr><td>Character</td><td>Speech</td></tr><tr><td>The multitude</td><td>The messiah! Show us the messiah!</td></tr><tr><td>Brians mother</td><td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td></tr><tr><td>The multitude</td><td>Who are you?</td></tr><tr><td>Brians mother</td><td>I'm his mother; that's who!</td></tr><tr><td>The multitude</td><td>Behold his mother! Behold his mother!</td></tr></table>
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace CsvToHtml
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string csv =
|
||||
@"Character,Speech
|
||||
The multitude,The messiah! Show us the messiah!
|
||||
Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>
|
||||
The multitude,Who are you?
|
||||
Brians mother,I'm his mother; that's who!
|
||||
The multitude,Behold his mother! Behold his mother!";
|
||||
|
||||
Console.Write(ConvertCsvToHtmlTable(csv, true));
|
||||
}
|
||||
|
||||
private static string ConvertCsvToHtmlTable(string csvText, bool formatHeaders)
|
||||
{
|
||||
var rows =
|
||||
(from text in csvText.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) /* Split the string by newline,
|
||||
* removing any empty rows. */
|
||||
select text.Split(',')).ToArray(); // Split each row by comma.
|
||||
|
||||
string output = "<table>"; // Initialize the output with the value of "<table>".
|
||||
|
||||
for (int index = 0; index < rows.Length; index++) // Iterate through each row.
|
||||
{
|
||||
var row = rows[index];
|
||||
var tag = (index == 0 && formatHeaders) ? "th" : "td"; /* Check if this is the first row, and if to format headers.
|
||||
* If so, then set the tags as table headers.
|
||||
* Otherwise, set the tags as table data. */
|
||||
|
||||
output += "\r\n\t<tr>"; // Add table row tag to output string.
|
||||
|
||||
// Add escaped cell data with proper tags to output string for each cell in row.
|
||||
output = row.Aggregate(output,
|
||||
(current, cell) =>
|
||||
current +
|
||||
string.Format("\r\n\t\t<{0}>{1}</{0}>", tag, WebUtility.HtmlEncode(cell)));
|
||||
|
||||
output += "\r\n\t</tr>"; // Add closing table row tag to output string.
|
||||
}
|
||||
|
||||
output += "\r\n</table>"; // Add closing table tag to output string.
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<table>
|
||||
<tr>
|
||||
<th>Character</th>
|
||||
<th>Speech</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>The messiah! Show us the messiah!</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Brians mother</td>
|
||||
<td><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>Who are you?</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Brians mother</td>
|
||||
<td>I'm his mother; that's who!</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>The multitude</td>
|
||||
<td>Behold his mother! Behold his mother!</td>
|
||||
</tr>
|
||||
</table>
|
||||
Loading…
Add table
Add a link
Reference in a new issue