在 ArrayList 中格式化和替换 和 ,并获取格式化的 ArrayList

本文关键字:格式化 ArrayList 获取 TD TR 替换 | 更新日期: 2023-09-27 17:56:48

由于我无法格式化TD和TR的HTML格式(因为 StackOverflow.com 有一个自动HTML格式化程序,导致编写确切代码的问题,例如TD和TR),所以请考虑以下格式的建议文本:

<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 ar3 = (ArrayList)Session["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>



我所要做的就是格式化这个 ArrayList(ar3),这样我就可以在另一个 ArrayList(例如 ResultArList)中拥有从开始 TR 和 TD 开始到关闭 TR 和 TD 结束的各个记录。
然后,此 ResultArList 将用于电子邮件中继和一些纯文本日志(在数据库中创建的自定义表)。

ResultArList应具有以下记录:
结果ArList[0]=FO 特别添加 (注释, 部分 #, RFQ #) - 13, 13, 13
结果ArList[1]=FO 特别添加 (注释, 部分 #, RFQ #) - 14, 14, 14
结果ArList[2]=FO 特别添加(注释,部分 #,RFQ #) - 15, 15, 15
结果ArList[3]=FO 特别添加 (注释, 部分 #, RFQ #) - 16, 16, 16

在 ArrayList ar3 中,这些值的数量是无限的,但上述 HTML 的格式是恒定的。

请帮助我如何自定义格式化我的数组列表并创建一个新的格式化数组列表。

在 ArrayList 中格式化和替换 <TR> 和 <TD>,并获取格式化的 ArrayList

如果我正确理解您的问题,您可以使用正则表达式来提取标签之间的任何内容; 例如:

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();