public string heightlight(string ostr)
{
string[] spliter = kyd.Split(new string[] { " ", "+" }, System.StringSplitOptions.RemoveEmptyEntries);
string tempstr = "";
for (int i = 0; i < spliter.Length; i++)
{
tempstr += "(" + spliter[i] + ")|";
}
MatchCollection mc = Regex.Matches(ostr, tempstr.Substring(0, tempstr.Length - 1), RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
if (mc == null) { return ostr; }
else
{
for (int i = 0; i < mc.Count; i++)
{
ostr = ostr.Replace(mc[i].Value, "<font color='red'>" + mc[i].Value + "</font>");
} }
return ostr;
}这个方法有问题,生成的html代码出现了
<li class="inf"><a href="http://www.jingyivalve.com/" target="_blank">Brass Ball <font color='red'><font color='red'><font color='red'>Valve</font></font></font>s,Radiator Heating <font color='red'><font color='red'><font color='red'>Valve</font></font></font>s Supplier,Brass Check <font color='red'><font color='red'><font color='red'>Valve</font></font></font>s Manufacturer,Jingyi</a><br />
<b>Jingyi,established in 1985,<font color='red'>China</font>,offers brass ball <font color='red'><font color='red'><font color='red'>valve</font></font></font>s,check and adiator heating <font color='red'><font color='red'><font color='red'>valve</font></font></font>s,LPG <font color='red'><font color='red'><font color='red'>valve</font></font></font>s,bibcock,taps,pipe fittings,sanitary ware...,at high quality,low price,used for household,factories,construction base.</b><br />
<a href="http://www.jingyivalve.com/" target="_blank">http://www.jingyi<font color='red'>valve</font>.com/</a></li> 这样的现象
该怎么修改啊!谢谢
{
string[] spliter = kyd.Split(new string[] { " ", "+" }, System.StringSplitOptions.RemoveEmptyEntries);
string tempstr = "";
for (int i = 0; i < spliter.Length; i++)
{
tempstr += "(" + spliter[i] + ")|";
}
MatchCollection mc = Regex.Matches(ostr, tempstr.Substring(0, tempstr.Length - 1), RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
if (mc == null) { return ostr; }
else
{
for (int i = 0; i < mc.Count; i++)
{
ostr = ostr.Replace(mc[i].Value, "<font color='red'>" + mc[i].Value + "</font>");
} }
return ostr;
}这个方法有问题,生成的html代码出现了
<li class="inf"><a href="http://www.jingyivalve.com/" target="_blank">Brass Ball <font color='red'><font color='red'><font color='red'>Valve</font></font></font>s,Radiator Heating <font color='red'><font color='red'><font color='red'>Valve</font></font></font>s Supplier,Brass Check <font color='red'><font color='red'><font color='red'>Valve</font></font></font>s Manufacturer,Jingyi</a><br />
<b>Jingyi,established in 1985,<font color='red'>China</font>,offers brass ball <font color='red'><font color='red'><font color='red'>valve</font></font></font>s,check and adiator heating <font color='red'><font color='red'><font color='red'>valve</font></font></font>s,LPG <font color='red'><font color='red'><font color='red'>valve</font></font></font>s,bibcock,taps,pipe fittings,sanitary ware...,at high quality,low price,used for household,factories,construction base.</b><br />
<a href="http://www.jingyivalve.com/" target="_blank">http://www.jingyi<font color='red'>valve</font>.com/</a></li> 这样的现象
该怎么修改啊!谢谢
string[] spliter = kyd.Split(new string[] { " ", "+" }, System.StringSplitOptions.RemoveEmptyEntries);
string tempstr = "";
string ostr = @"<li class=""inf""> <a href=""http://www.jingyivalve.com/"" target=""_blank"">Brass Ball <font color='red'> <font color='red'> <font color='red'>Valve </font> </font> </font>s,Radiator Heating <font color='red'> <font color='red'> <font color='red'>Valve </font> </font> </font>s Supplier,Brass Check <font color='red'> <font color='red'> <font color='red'>Valve </font> </font> </font>s Manufacturer,Jingyi </a> <br />
<b>Jingyi,established in 1985, <font color='red'>China </font>,offers brass ball valve s,check and adiator heating <font color='red'> <font color='red'> <font color='red'>valve </font> </font> </font>s,LPG <font color='red'> <font color='red'> <font color='red'>valve </font> </font> </font>s,bibcock,taps,pipe fittings,sanitary ware...,at high quality,low price,used for household,factories,construction base. </b> <br />
<a href=""http://www.jingyivalve.com/"" target=""_blank"">http://www.jingyi valve.com/ </a> </li> 这样的现象
";
for (int i = 0; i < spliter.Length; i++)
{
//tempstr += "(" + spliter[i] + ")|";
ostr = ostr.Replace(spliter[i], "<font color='red'>" + spliter[i] + "</font>");
}
就是,把你的待替换的string贴出来看一下,要不然都不知道你的原字符串怎么样的,
怎么帮你搞啊
我的关键字是valve ,html中是valve