Consider a simplified CSV format where all rows are separated by a newline
and all columns are separated by commas.

No commas are allowed as field data, but the data may contain
other characters and character sequences that would
normally be   escaped   when converted to HTML



Task

Create a function that takes a string representation of the CSV data
and returns a text string of an HTML table representing the CSV data.

Use the following data as the CSV text to convert, and show your output.

 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!


Extra credit

Optionally allow special formatting for the first row of the table as if it is the tables header row
(via <thead> preferably; CSS if you must).




Imports Microsoft.VisualBasic.FileIO
 
Module Program
    Sub Main(args As String())
        Dim parser As TextFieldParser
        Try
            If args.Length > 1 Then
                parser = My.Computer.FileSystem.OpenTextFieldParser(args(1), ",")
            Else
                parser = New TextFieldParser(Console.In) With {.Delimiters = {","}}
            End If
 
            Dim getLines =
            Iterator Function() As IEnumerable(Of String())
                Do Until parser.EndOfData
                    Yield parser.ReadFields()
                Loop
            End Function
 
            Dim result = CSVTOHTML(getLines(), If(args.Length > 0, Boolean.Parse(args(0)), False))
 
            Console.WriteLine(result)
        Finally
            If parser IsNot Nothing Then parser.Dispose()
        End Try
    End Sub
 
    Function CSVTOHTML(lines As IEnumerable(Of IEnumerable(Of String)), useTHead As Boolean) As XElement
        Dim getRow = Function(row As IEnumerable(Of String)) From field In row Select <td><%= field %></td>
 
        CSVTOHTML =
<table>
    <%= From l In lines.Select(
            Function(line, i)
                If useTHead AndAlso i = 0 Then
                    Return <thead><%= getRow(line) %></thead>
                Else
                    Return <tr><%= getRow(line) %></tr>
                End If
            End Function) %>
</table>
    End Function
End Module