string strReplacement = @"$1<a href=""http://www.wuanju.com"" target=""_blank"" title=""${tag}"">${tag}</a>";
我想把http://www.wuanju.com换成动态的应该怎么写?
string strReplacement = @"$1<a href="""+link+""" target=""_blank"" title=""${tag}"">${tag}</a>";
这样写通不过。。。
全部代码是这样的,我做的关键词替换,链接是动态的,网上看到的是写死的。应该怎么改?
Regex reg = new Regex(@"(?i)(?:^|(?<!<a\b(?>[^<>]*))>)(?>[^<>]*)(?:<|$)");
string temp = string.Empty;
string result = reg.Replace(content, delegate(Match m)
{
temp = m.Value;
foreach (Keyword k in keywordList)
{
string strReplacement = @"$1<a href=""http://www.wuanju.com"" target=""_blank"" title=""${tag}"">${tag}</a>";
temp = Regex.Replace(temp, @"(?is)^((?:(?:(?!" + Regex.Escape(k.KeywordName) + @"|</?a\b).)*<a\b(?:(?!</?a\b).)*</a>)*(?:(?!"
+ Regex.Escape(k.KeywordName) + @"|</?a\b).)*)(?<tag>" + Regex.Escape(k.KeywordName) + @")", strReplacement);
}
return temp;
});
return result;
string strReplacement = @"$1<a href=""#link#"" target=""_blank"" title=""${tag}"">${tag}</a>";
strReplacement =strReplacement .Replace("#link#",link);
谢谢