突出显示搜索结果中的单词 [英] Highlight Search Word in Results

查看:51
本文介绍了突出显示搜索结果中的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


我有一个小功能来突出显示文本。


功能亮点(vFind,vSearch)

Dim RegEx

设置RegEx =新RegExp

RegEx.Pattern = vFind

RegEx.IgnoreCase = True

Highlight = RegEx.Replace(vSearch,"< span class ="" Highlight"">"& vFind&

"< / span> ;")

设置RegEx = Nothing

结束功能


唯一的问题是,如果我搜索什么,,某事当被搜索的字符串实际包含Something时,会突出显示



这不是关于区分大小写的搜索,这是关于显示实际的

匹配而不是搜索的内容。希望这是有道理的。


例如:


Response.Write突出显示(某事,你看到了什么关于

Mary?")


给:


你见过< span class ="突出显示" >东西< /跨度>关于玛丽?


虽然这没关系,如果它实际突出了比赛

而不是''发现,即:


你见过< span class =" Highlight"> Something< / span>关于玛丽?


我已经查看了一些文档,似乎要做我想要的b $ b想要使用execute方法然后搜索比赛

集合。有没有人有这样的示例代码我可以

_borrow_?


我的功能很好而且很小,所以不得不去羞耻

更大的东西,(又称性能下降),如果一个简单的改变可以

我的功能。


我是我也注意到JScript方法的建议,因为我注意到了这些

特殊字符$ 0 - $ 9虽然MSDN有点缺乏示例代码

对于像我这样的新手。


MTIA

David

解决方案

0 -


9虽然MSDN对于像我这样的新手来说有点缺乏样本代码




MTIA

David


功能突出显示(sFind,sSearch)

突出显示=替换(sSearch,sFind,"< span class ="" highlight"">"& sFind

&"< / span>" ;)

结束功能


-


问候


Steven Burn

Ur IT Mate Group
www.it-mate.co.uk


保持免费!

" David Morgan" <哒*** @ davidmorgan.me.uk>在消息中写道

新闻:#y ************** @ TK2MSFTNGP11.phx.gbl ...

你好

我有一个小功能来突出显示文本。

功能突出显示(vFind,vSearch)
Dim RegEx
设置RegEx =新RegExp RegEx.Pattern = vFind
RegEx.IgnoreCase = True
突出显示= RegEx.Replace(vSearch,"< span class =""<>">"& vFind& ;
"< / span>")
设置RegEx = Nothing
结束功能

唯一的问题是,如果我搜索某事 ;,某事物当被搜索的字符串实际包含Something时,会突出显示

这不是区分大小写的搜索,而是显示
实际匹配而不是搜索的内容。希望这是有道理的。

例如:

Response.Write突出显示(某事,你见过某事吗?玛丽?)

Gives:

你见过< span class ="突出显示>>某事< / span>关于玛丽?

虽然这没关系,如果真的突出了比赛
而不是''发现,那就太棒了,即:

你见过吗? < span class ="突出显示"> Something< / span>关于Mary?

我已经查看了一些文档,似乎要做我想要的事情涉及使用execute方法然后搜索
匹配集合。有没有人有这样的示例代码我可以
_borrow_?

我的功能很好而且很小,不得不去更大的东西,(如果我的功能可以进行简单的改变,那么性能就会降低。

我对JScript方法的建议也很开心,因为我注意到这些
特殊字符

Hello

I have a little function to highlight text if it exists.

Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = vFind
RegEx.IgnoreCase = True
Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">" & vFind &
"</span>")
Set RegEx = Nothing
End Function

The only problem is, that if I search for "something", "something" appears
highlighted when the string being searched actually contained "Something".
This is not about case sensitive searching, this is about showing the actual
match rather than what was being searched for. Hope that makes sense.

For example:

Response.Write Highlight("something", "Have you seen Something About
Mary?")

Gives:

Have you seen <span class="Highlight">something</span> About Mary?

Whilst this is ok, it would be great if it actually highlighted the match
rather than the ''find, i.e:

Have you seen <span class="Highlight">Something</span> About Mary?

I have looked in to the documentation a bit and it seems that to do what I
want involves using the execute method and then hunting through the matches
collection. Does anyone have any sample code for this that I could
_borrow_?

My function is nice and small and it would be a shame to have to go for
something bigger, (a.k.a. performance degradation), if a simple change can
be made to my function.

I am open to suggestions on the JScript approach also as I notice these
special characters $0 - $9 although MSDN is somewhat lacking in sample code
for a novice like me.

MTIA

David

解决方案

0 -


9 although MSDN is somewhat lacking in sample code
for a novice like me.

MTIA

David


Function Highlight(sFind, sSearch)
Highlight = Replace(sSearch, sFind, "<span class=""highlight"">" & sFind
& "</span>")
End Function

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:#y**************@TK2MSFTNGP11.phx.gbl...

Hello

I have a little function to highlight text if it exists.

Function Highlight(vFind, vSearch)
Dim RegEx
Set RegEx = New RegExp
RegEx.Pattern = vFind
RegEx.IgnoreCase = True
Highlight = RegEx.Replace(vSearch, "<span class=""Highlight"">" & vFind &
"</span>")
Set RegEx = Nothing
End Function

The only problem is, that if I search for "something", "something" appears
highlighted when the string being searched actually contained "Something".
This is not about case sensitive searching, this is about showing the actual match rather than what was being searched for. Hope that makes sense.

For example:

Response.Write Highlight("something", "Have you seen Something About
Mary?")

Gives:

Have you seen <span class="Highlight">something</span> About Mary?

Whilst this is ok, it would be great if it actually highlighted the match
rather than the ''find, i.e:

Have you seen <span class="Highlight">Something</span> About Mary?

I have looked in to the documentation a bit and it seems that to do what I
want involves using the execute method and then hunting through the matches collection. Does anyone have any sample code for this that I could
_borrow_?

My function is nice and small and it would be a shame to have to go for
something bigger, (a.k.a. performance degradation), if a simple change can
be made to my function.

I am open to suggestions on the JScript approach also as I notice these
special characters


这篇关于突出显示搜索结果中的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆