2013-01-31 65 views
-2

由於我無法格式化TD和TR的HTML格式(因爲StackOverflow.com有一個自動HTML格式化程序,它會導致問題編寫的確切碼例如TD & TR),所以麻煩考慮所提出的文本的格式如下: -

格式並替換<TR>和<TD> ArrayList中並獲得格式化ArrayList

<tr> 
    <td>FO Special Added (Comments, Part #, RFQ #) - 13, 13, 13</td> 
</tr> 
<tr> 
    <td>FO Special Added (Comments, Part #, RFQ #) - 14, 14, 14</td> 
</tr> 

我有正在從一個會話變量填充的ArrayList: -
ArrayList的AR3 =(ArrayList的)會話[ 「ARR3」];

Session["arr3"] = "<tr> <td>FO Special Added (Comments, Part #, RFQ #) - 13, 13, 13</td> </tr><tr> <td>FO Special Added (Comments, Part #, RFQ #) - 14, 14, 14</td> </tr><tr> <td>FO Special Added (Comments, Part #, RFQ #) - 15, 15, 15</td> </tr> <td>FO Special Added (Comments, Part #, RFQ #) - 16, 16, 16</td> </tr> 



所有我想要做的就是以這樣的方式,我可以在關閉TR & TD從開始TR & TD和結束開始單獨記錄格式化此ArrayList(AR3) ,在另一個ArrayList(例如ResultArList)中。
此ResultArList將用於電子郵件中繼和一些純文本日誌(在數據庫中創建自定義表)。

的ResultArList應具有記錄爲: -
ResultArList [0] = FO特別添加(評論,零件編號,RFQ#) - 13,圖13,13
ResultArList [1] = FO特別添加(評論,部件編號,詢價#) - 14,14,14
ResultArList [2] = FO Special Added(評論,部件編號,RFQ#) - 15,15,15
ResultArList [3] = FO Special Added評論,部件編號,RFQ#) - 16,16,16

ArrayList ar3中這些值的數量是無限的,但上述HTML的格式是不變的。

請幫助我如何自定義格式化我的ArrayList並創建一個新的格式化ArrayList。

+0

花幾分鐘時間來學習如何格式化代碼。你的問題是不可讀的。 –

+1

您需要將代碼格式化爲代碼,以便它不會呈現爲HTML。用你在那裏得到的東西,它太破壞了,甚至不可讀。 – Servy

+1

你真的不應該在C#中使用'ArrayList';你應該使用通用的'List'。 – Servy

回答

1

如果我正確理解你的問題,你可以使用正則表達式來提取標籤之間的任何內容;例如:

var regex = new System.Text.RegularExpressions.Regex(@"(?<=<td>).+?(?=</td>)", RegexOptions.Compiled | RegexOptions.IgnoreCase); 
var text = "<tr> <td>FO Special Added (Comments, Part #, RFQ #) - 13, 13, 13</td> </tr><tr> <td>FO Special Added (Comments, Part #, RFQ #) - 14, 14, 14</td> </tr><tr> <td>FO Special Added (Comments, Part #, RFQ #) - 15, 15, 15</td> </tr> <td>FO Special Added (Comments, Part #, RFQ #) - 16, 16, 16</td> </tr>"; 
var matches = regex.Matches(text); 

var results = matches.Cast<Match>() 
    .Select(match => match.Value) 
    .ToList(); 
+0

gerrod!非常感謝您的解決方案,它解決了我的問題。 –

相關問題