textRange的findText()方法详解
来源:互联网 发布:淘宝直通车怎样出价 编辑:程序博客网 时间:2024/05/17 18:19
呵呵,一直以来都是去别人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.
<HTML><BODY>Leonardo da Vinci was one of the great masters of the High Renaissance, especially in painting, sculpture, architecture, engineering, and science.</BODY></HTML><SCRIPT> var oRange = document.body.createTextRange(); // record the current position in a bookmark var sBookMark = oRange.getBookmark(); // true - case-insensitive and partial word match oRange.findText('leo'); // reset the range using the bookmark oRange.moveToBookmark(sBookMark); // false - matches whole words only oRange.findText('engineer', 0, 2); oRange.moveToBookmark(sBookMark); // false - case-sensitive oRange.findText('high', 0, 4); oRange.moveToBookmark(sBookMark); // true - case-sensitive and matches whole words oRange.findText('Leonardo', 0, 6); // the degenerate case oRange.moveToBookmark(sBookMark); // make the range degenerate oRange.collapse(); // false - must specify large character count in this case oRange.findText('Leonardo', 0, 6); // true - no third parameter passed, so no count needed oRange.findText('Leonardo'); // true - a large count covers the range oRange.findText('Leonardo', 1000000000, 6); </SCRIPT> |
- textRange的findText()方法详解
- findtext
- html TextRange的使用
- TextRange
- 比较深入的认识一下textrange
- DHTML --TextRange对象的使用
- TextRange对象与Range对象的使用
- TextRange对象的学习(一)
- 当IHTMLTxtRange::findText Method查找不到字符串的时候
- javascript moveStart和moveEnd方法(TextRange对象--查找与选择)
- JS moveStart和moveEnd方法(TextRange对象--查找与选择)
- 使用TextRange获取输入框中光标的位
- 使用TextRange获取输入框中光标的位置
- 使用TextRange获取输入框中光标的位置
- 使用TextRange获取输入框中光标的位置
- TextRange对象,动态HTML(DHTML)的高级特性
- Range、Selection、TextRange对象的区别与关系
- TextRange对象
- 1111111111
- ActionScript 3.0实例—Loading
- 重温-Window(NT)启动过程
- X11下xorg.conf配置说明
- 关于FLV视频没缓冲拖动的思路
- textRange的findText()方法详解
- CSDN这个博客错误为什么这么多天都没有修复,太失望了!!!
- 人生程序
- Axis2 基础
- VC中radio的用法[转]
- 将其他程序中的大纲文本插入到 PowerPoint 演示文稿中
- PCB板上的杂质对低功耗应用的影响
- SQL Server 日期转换格式
- 将 pptx 中的大纲以 docx 格式导出