【发布时间】:2011-11-08 09:32:37
【问题描述】:
我想在我的 ASP.NET MVC 3 网站上进行搜索,所以对于搜索我必须找到匹配的模式,并且用粗体字替换匹配的部分(我使用那个 html <strong> 标签) .
所以我的控制器中有这个
string[] words=content.Split(' ');
foreach (Thread thread in context.Threads)
{
foreach (string word in words)
{
if (thread.Title.ToLower().Contains(word.ToLower()))
{
thread.Title=Regex.Replace(thread.Title,word,String.Format("<strong>{0}</strong>","$0"),RegexOptions.IgnoreCase);
}
}
}
所以,如果我搜索new thread a,它会找到像New thrEAd 这样的线程。
但是在 html 中它使我的字符串变成那样
<strong>New</strong> <strong>thrE<strong>A</strong>d</strong>
所以我想从 a 中删除 strong 标签,因为它是双粗体... 我该怎么做?
如果你有有趣的方法来进行我的搜索,我也很高兴听到你的建议。
【问题讨论】:
-
很抱歉这个问题,但我需要了解这一点。所以你有一个单词列表,如果它们匹配,它们应该用 括起来。是这个问题吗?
标签: c# html regex asp.net-mvc-3 search