日期:2014-05-20  浏览次数:20454 次

搜索后的关键字高亮显示(急)100分
一个字符串如:str = "<p>依据季节变化和茶树新梢生长的间歇<a href='#?id=2008'>年份2008</a>平常清明过后春茶开始大</p>"
我现在只想找到非html代码中的2008,并高亮显示,效果如下:
str = "<p>依据季节变化和茶树新梢生长的间歇<a href='#?id=2008'>年份<label class='sr_word01'>2008</label></a>平常清明过后春茶开始大</p>"

如果用 str..Replace("2008","<label class='sr_word01'>2008</label>") 就会把链接地址的参数id=2008中的2008也替换掉了。

如何才能实现?请高手指点

------解决方案--------------------
InnerText;
------解决方案--------------------
用正则表达市啊

------解决方案--------------------
Function ReplaceTest( strPatrn, ItemInfo )
Dim regEx
Dim str
Dim patrnArry
Dim patrn
Dim replStr
Dim nRTCount
Dim nArrayCount

str = ""
patrn = ""
replStr = ""
nArrayCount = 1

patrnArry = split( strPatrn, " " )

For nRTCount = 0 To UBound( patrnArry )
If IsEmptyString( Trim( patrnArry( nRTCount ) ) ) = false Then
replStr = replStr & "<font color='red'>$" & nArrayCount & "</font>"
nArrayCount = nArrayCount + 1
End If
Next

For nRTCount = 0 To UBound( patrnArry )
If IsEmptyString( Trim( patrnArry( nRTCount ) ) ) = false Then
patrn = patrn & "(" &Trim( patrnArry( nRTCount ) ) & ")|"
End If
Next

patrn = mid( patrn, 1, len( patrn ) - 1 )

Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
ReplaceTest = regEx.Replace(ItemInfo, replStr)

End Function
------解决方案--------------------
C# code

#region 返回搜索红色关键词 replacered
    public static string replacered(string title, string redkey)
    {
        title = title.Replace(redkey, "<font color='#ff0000'>" + redkey + "</font>");
        return title;
    }
    #endregion

------解决方案--------------------
探讨
引用:
C# code
#region 返回搜索红色关键词 replacered
public static string replacered(string title, string redkey)
{
title = title.Replace(redkey, " <font color='#ff0000'>" + redkey + " </font>");
return title;
}
#endregion


<%# Member.replacered(Eval("aAbout").ToString(),keyword) %>

------解决方案--------------------
帮顶
------解决方案--------------------
HTML code
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a href='#?id=2008' id="a1">年份2008</a>
    <script>
    document.getElementById("a1").innerHTML=document.getElementById("a1").innerHTML.replace("2008","<font color='red'>2008</font>");
    </script>
    </div>
    </form>
</body>
</html>

------解决方案--------------------
帮助楼主顶一下,顺便自己也学习一下,o(∩_∩)o...
------解决方案--------------------
学习了....