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> 这样的现象
该怎么修改啊!谢谢

解决方案 »

  1.   

    string kyd = "value base";
                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>");
                }
      

  2.   

    <font color='red'> <font color='red'> <font color='red'>valve </font> </font> </font>问题主要就出现在这里 多来来font标签了
      

  3.   

    不会吧,你给我一个关键字列表和一个待替换的string看看。
      

  4.   


    就是,把你的待替换的string贴出来看一下,要不然都不知道你的原字符串怎么样的,
    怎么帮你搞啊
      

  5.   

    不是代码的问题,是关键字的问题。
    我的关键字是valve ,html中是valve
      

  6.   

     我的关键词是 china valve 却只有valve红色
      

  7.   

    ostr = Regex.Replace(ostr,spliter[i], "<font color='yellow'>" + spliter[i] + "</font>", RegexOptions.IgnoreCase);