How to resolve the algorithm CSV to HTML translation step by step in the OpenEdge/Progress programming language
How to resolve the algorithm CSV to HTML translation step by step in the OpenEdge/Progress 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 OpenEdge/Progress programming language
Source code in the openedge/progress programming language
FUNCTION csvToHtml RETURNS CHARACTER (
i_lhas_header AS LOGICAL,
i_cinput AS CHARACTER
):
DEFINE VARIABLE coutput AS CHARACTER NO-UNDO.
DEFINE VARIABLE irow AS INTEGER NO-UNDO.
DEFINE VARIABLE icolumn AS INTEGER NO-UNDO.
DEFINE VARIABLE crow AS CHARACTER NO-UNDO.
DEFINE VARIABLE ccell AS CHARACTER NO-UNDO.
coutput = "~n~t
".
DO irow = 1 TO NUM-ENTRIES( i_cinput, "~n":U ):
coutput = coutput + "~n~t~t
~n".
RETURN coutput.
END FUNCTION. /* csvToHtml */
MESSAGE
csvToHtml(
TRUE,
"Character,Speech" + "~n" +
"The multitude,The messiah! Show us the messiah!" + "~n" +
"Brians mother,".
crow = ENTRY( irow, i_cinput, "~n":U ).
DO icolumn = 1 TO NUM-ENTRIES( crow ):
ccell = ENTRY( icolumn, crow ).
coutput = coutput + "~n~t~t~t" + IF i_lhas_header AND irow = 1 THEN " ".
END.
coutput = coutput + "~n~t" ELSE " ".
coutput = coutput + REPLACE( REPLACE( REPLACE( ccell, "&", "&" ), "<", "<" ), ">", ">" ).
coutput = coutput + IF i_lhas_header AND irow = 1 THEN "" ELSE " ".
END.
coutput = coutput + "~n~t~t
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!
You may also check:How to resolve the algorithm Align columns step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Naming conventions step by step in the Go programming language
You may also check:How to resolve the algorithm Bitmap/Histogram step by step in the Racket programming language
You may also check:How to resolve the algorithm Hamming numbers step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the C2 programming language