Most efficient way to parse delimited into html table c# -


i've got following delimited string pairs:

1,5|2,5|3,5 

i want create table follows:

      < table>      < tr>< td>1< /td>< td>5< /td>< /tr>      < tr>< td>2< /td>< td>5< /td>< /tr>      < tr>< td>3< /td>< td>5< /td>< /tr>      < /table>     

what's efficient way in c#?

version 1: straight-forward

string html = "<table>"; array.foreach<string>("1,5|2,5|3,5".split('|'),r => {   html += "<tr>";   array.foreach(r.split(','),c =>   {     html += string.format("<td>{0}</td>", c);   });   html += "</tr>"; }); html += "</table>"; 

untested, of sort? take back, battle tested , working.

version two, less delegate:

string html = "<table>"; foreach (string r in "1,5|2,5|3,5".split('|')) {   html += "<tr>";   foreach (string c in r.split(','))     html += string.format("<td>{0}</td>", c);   html += "</tr>"; } html += "</table>"; 

both versions in working demo.

and version includes stringbuilder


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -