【发布时间】:2015-12-18 22:28:11
【问题描述】:
我的 asp 页面中有一个 TemplateField,它绑定到一个名为 Descript 的数据类型为字符串的列,该列存储帮助台票证的注释条目,并在字符串的开头附加最新的注释。
<asp:TemplateField HeaderText="Notes" SortExpression="DESCRIPT">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("DESCRIPT") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DESCRIPT") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
在这个 Descript 字符串中可能会出现多个日期和时间,后跟时区、连字符、名称和一些文本。
例如:
2015 年 12 月 4 日上午 8:34 中部标准时间 - 最后,第一个
我要做的是在每次出现相同模式的情况时在此信息之前插入一个新行(或 2 个),以便在每个新条目出现时提供一些视觉中断。
我的猜测是我需要使用 RegEx 来匹配日期/时间模式并存储在一个变量中,然后用新行 + 变量替换该信息。
类似这样的:
string text = Descript.ToString();
string pattern = @"/[0-1]\d\/[0-3]\d\/\d{4} [0-1]\d:[0-5]\d [aApP][mM]/";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
Match m = r.Match(text);
while (m.Success)
{
//here is where I am stuck
//I expect to have something like Replace (found string) with Environment.NewLine + (found string)
}
如果我可以修改我的 SQL 选择语句,我非常乐意这样做。
Select ID, Name, Descript
From Table
这条 SQL 语句可能返回超过 100 条记录,并且每个 Descript 记录中可能存在多次日期时间模式。
感谢任何帮助!
【问题讨论】: