Jump to content

CSV to HTML translation: Difference between revisions

m (→‎{{header|C}}: remove a warning)
(→‎{{header|J}}: Add draft)
Line 113:
return EXIT_SUCCESS;
}</lang>
 
=={{header|J}}==
'''Solution'''
<lang j>require 'strings tables/csv'
encodeHTML=: ('&';'&amp;';'<';'&lt;';'>';'&gt;')&stringreplace
cell=: '<td>' , ,&'</td>'
row=: <@('<tr>' , ,&('</tr>',LF))@;"1
table=: ('<table>' , ,&'</table>')@;"1
makeHTMLtablefromCSV=: [: table [: row [: cell&.> fixcsv@encodeHTML</lang>
 
'''Example'''
<lang j> csvstrng=: noun define
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!
)</lang>
 
<pre> makeHTMLtablefromCSV csvstrng
<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>&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></pre>
 
=={{header|OCaml}}==
892

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.