How to resolve the algorithm CSV to HTML translation step by step in the Nanoquery programming language
How to resolve the algorithm CSV to HTML translation step by step in the Nanoquery programming language
Table of Contents
Problem Statement
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
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.
Optionally allow special formatting for the first row of the table as if it is the tables header row
(via preferably; CSS if you must).
Let's start with the solution:Step by Step solution about How to resolve the algorithm CSV to HTML translation step by step in the Nanoquery programming language
Source code in the nanoquery programming language
// a method that converts a csv row into a html table row as a string
def toHtmlRow(record, tag)
htmlrow = "\t
\n"
// loop through the values in the current csv row
for i in range(1, len(record))
htmlrow = htmlrow + "\t\t<" + tag + ">" + (record ~ i) + "" + tag + ">\n"
end for
return htmlrow + "\t \n"
end def
// get the name of the csv file then open it
print "filename: "
input fname
open fname
// allocate a string to hold the table
htmltable = "\n"
// add the column names to the table (#0 returns column names as a record object)
htmltable = (htmltable + toHtmlRow(#0, "th"))
// add all other rows to the table
for i in range(1, $dbsize)
htmltable = (htmltable + toHtmlRow(#i, "td"))
end for
// close the html table
htmltable = htmltable+"
"
println htmltable
You may also check:How to resolve the algorithm Array length step by step in the Batch File programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the REXX programming language
You may also check:How to resolve the algorithm Terminal control/Ringing the terminal bell step by step in the bc programming language
You may also check:How to resolve the algorithm Fractran step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Feigenbaum constant calculation step by step in the Go programming language