使用 System.Text.RegularExpressions (Regex) 搜索模式以替换表格标签:
用空白替换<tr><th>
和,<tr><td>
replace</th></tr>
和</td></tr>
with^^~~~~~~~~~~^^
表示结束线。
替换</td><td>
为||^^^^^^^^^||
表示分隔符
string html = // your html table goes here
string[] lines = html.Split(new string[] { "^^~~~~~~~~~~^^" }, StringSplitOptions.None);
// now your html table is divided into lines, which means rows
// lines[0] = // the header
// lines[1] = // row 1
// lines[2] = // row 2
// lines[3] = // row 3
// ...
// ...
// line 1 is the header/column name
string[] columns = lines[0].Split(new string[] { "||^^^^^^^^^||" }, StringSplitOptions.None);
// columns[0] = // 1st column name
// columns[1] = // 2nd column name
// columns[2] = // 3rd column name
// ...
// ...
for (int i = 1; i < lines.Length; i++)
{
string[] data = lines[i].Split(new string[] { "||^^^^^^^^^||" }, StringSplitOptions.None);
// data[0] = // 1st data
// data[1] = // 2nd data
// data[2] = // 3rd data
// ...
// ...
}