My Problem is for particular case occuring in my project.
in my Html document,
i want to
replace <td>
with <td class=”right”>
for all tds except first one in a <tr>
tag. (if there is <tr>
inside a <tr>
tag then that also needs to be handled).
if input is like
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<tr>
output should be like
<tr>
<td>1</td>
<td class=”right”>2</td>
<td class=”right”>3</td>
<tr>
i have tried..this code..
public static string tableFormat(string html) // Add extra attribute to td
{
int start = 0, end = 0, trstart = 0, trend = 0;
// html = CleanUpXHTML(html); // clean unnecessary p tags
while (html.Contains("<tr>"))
{
//start=end;
trstart = html.IndexOf("<tr>", end);
if (trstart == -1)
break;
trend = html.IndexOf("</tr>", trstart);
start = html.IndexOf("<td>", trstart);
end = html.IndexOf("</td>", trend);
while (end < trend)
{
start = html.IndexOf("<td>", end);
html = html.Insert(start + 3, " class=\"right\"");
end = html.IndexOf("</td>", trstart);
}
}
return html;
}