使用System.Text.RegularExpressions(正則表達式)來搜索模式來替換表標籤:
更換<tr><th>
和<tr><td>
空白,
更換</th></tr>
和</td></tr>
與^^~~~~~~~~~~^^
指示端線。
取代</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
// ...
// ...
}
那你在「我打電話從服務器端的HTML。」是什麼意思?你是從服務器端創建這個html嗎?請提供更多詳細信息 –
表示我在.cs頁面中編寫了上述代碼 – Optimus