日期:2014-05-17 浏览次数:20431 次
DataTable dt = new System.Data.DataTable();
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("name", typeof(string));
dt.Rows.Add(1, "张一");
dt.Rows.Add(2, "李四");
string str = " 你好张一我很好,我是李四";
string pat = string.Join("
------解决方案--------------------
", dt.AsEnumerable().Select(t => t.Field<string>("name")).ToArray());
str = Regex.Replace(str, pat, delegate(Match m)
{
return @"<a href=""XXX.aspx?id=" + dt.Select("name='" + m.Value+"'").First().Field<int>("id") + "\">" + m.Value + "</a>";
});
DataTable dt = new DataTable();
dt.Columns.Add("id");
dt.Columns.Add("name");
dt.Rows.Add(new object[]{"1", "张一"});
dt.Rows.Add(new object[] { "2", "李四" });
dt.Rows.Add(new object[] { "3", "王五" });
string strText = " 你好张一我很好,我是李四,张一说,带上王五吧";
foreach (DataRow dr in dt.Rows)
{
strText=strText.Replace(dr["name"].ToString(),string.Format("<a href='?id={0}'>{1}</a>",dr["id"],dr["name"]));
}