findtext 方法学习收藏

阅读更多

createRange 中发现findText这个方法,找了篇文章收藏,谢过原作者

http://blog.csdn.net/jiangqiaohua/archive/2008/10/17/3091979.aspx

==============

呵呵,一直以来都是去别人BLOG搜刮资料

这次偶也写一点分享一下。

最近在做飞腾浏览器(FlyIe)的的查找功能,(打下广告@_@)

关键字高亮和向上向下查找都差不多了

遇到了全字匹配和区分大小写的问题。

后来到MSDN一查,原来findText()方法都有。

findText Method
Searches for text in the document and positions the start and end points of the range to encompass the search string.

Syntax


bFound = TextRange.findText(sText [, iSearchScope] [, iFlags])

Parameters

sText Required. String that specifies the text to find.
iSearchScope Optional. Integer that specifies the number of characters to search from the starting point of the range. A positive integer indicates a forward search; a negative integer indicates a backward search. 
iFlags Optional. Integer that specifies one or more of the following flags to indicate the type of search: 0 Default. Match partial words.


0 Default. Match partial words.
1 Match backwards.
2 Match whole words only.
4 Match case.
131072 Match bytes.
536870912 Match diacritical marks.
1073741824 Match Kashida character.
2147483648 Match AlefHamza character.

iFlags 参数为0表示部分匹配,比如

@a,@ADD,@a Abba @AB  超找@a 为四个

iFlags 参数为1表示查找最后一个关键字,比如

@a,@ADD,@a Abba @AB 查找@a 就到 @AB 这里去了

iFlags 参数为2表示全字匹配,比如

@a,@ADD,@a Abba @AB 查找@a 就到 只有一个就是 @a

iFlags 参数为3表示全字匹配,比如

@a,@ADD,@a Abba @AB 查找@a 就到 只有一个就是 @a

iFlags 参数为4表示大小写匹配,比如

@a,@ADD,@a Abba @AB 查找a 就到 只有三个

iFlags 参数为5表示按字节匹配

剩下几个参数不知道什么意思,也不重要就不说了。

 

 

那假如即要全字匹配又要大小写匹配怎么办呢?

很简单

If oRange.findText(nWord, , 2) Then
    If oRange.findText(nWord, , 4) Then
        nPosBM = oRange.getBookmark
        'Call oRange.moveToBookmark(nPosBM)
        Call oRange.Select
       
        FindWord2 = True
    End If
Else
    'Set nPosBM = Nothing
    nPosBM = vbNullString
    FindWord2 = False
End If

加个IF 循环就好了

 

 

 

 

其他参数就靠其他大虾解释了

This example creates a TextRange over the body of the document, and then uses the findText method to search for text with various flag combinations. The results are indicated in the example code comments.

 Copy Code


Leonardo da Vinci was one of the great masters of the High
Renaissance, especially in painting, sculpture, architecture,
engineering, and science.

 

你可能感兴趣的:(浏览器,Blog,.net,HTML)