CSV to HTML translation: Difference between revisions

Content added Content deleted
m (→‎{{header|C}}: remove spare </nowiki> - maybe insert some bonus "new lines"...)
(added OpenEdge solution)
Line 1,510: Line 1,510:
</tbody>
</tbody>
</table></lang>
</table></lang>

=={{header|OpenEdge/Progress}}==
<lang OpenEdge/Progress>
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 = "<html>~n~t<table>".
DO irow = 1 TO NUM-ENTRIES( i_cinput, "~n":U ):

coutput = coutput + "~n~t~t<tr>".
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 "<th>" ELSE "<td>".
coutput = coutput + REPLACE( REPLACE( REPLACE( ccell, "&", "&amp;" ), "<", "&lt;" ), ">", "&gt;" ).
coutput = coutput + IF i_lhas_header AND irow = 1 THEN "</th>" ELSE "</td>".

END.

coutput = coutput + "~n~t~t</tr>".
END.

coutput = coutput + "~n~t</table>~n</html>".

RETURN coutput.

END FUNCTION. /* csvToHtml */

MESSAGE
csvToHtml(
TRUE,
"Character,Speech" + "~n" +
"The multitude,The messiah! Show us the messiah!" + "~n" +
"Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>" + "~n" +
"The multitude,Who are you?" + "~n" +
"Brians mother,I'm his mother; that's who!" + "~n" +
"The multitude,Behold his mother! Behold his mother!"
)
VIEW-AS ALERT-BOX.</lang>
Output with header enabled
<lang html><html>
<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>&lt;angry&gt;Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!&lt;/angry&gt;</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>
</html></lang>


=={{header|Perl}}==
=={{header|Perl}}==