`

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
<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>

 

分享到:
评论

相关推荐

    Win32控件richedit,如何使用EM_FINDTEXT win32消息查找字符串

    win32 RichEdit控件支持大量单词。 我想在这种控件中找到一些字符串。 我在msdn上找到了win32消息EM_FINDTEXT。 如果找到了特殊字符串,则返回值为控件文本的索引。 我试过了,但是不起作用。 我...

    FindFiles.rar

    FindFiles.rar,基于c++编写,欢迎下载,谢谢!!

    通过JavaScript脚本复制网页上的一个表格

    测试 测试表格 测试表格 测试表格 ...继续在msdn中仔细查阅了一下,createTextRange()返回的是一个 TextRange 对象,继续查阅 TextRange 对象,发现其有很多方法,先试了试findText方法,发

    TextFind2:TextFind2是用于搜索TXT文件的程序-开源

    TextFind2是用于搜索TXT文件的程序。 更具体地说,用于在书中搜索,其中包含写成一百四十年(140)的数字。 它使用MMX指令一次比较8个字符。 它还能够提取每一行,并且您可以将其另存为TXT或RTF文件。...

    C#浏览器编程,学习使用

    //本浏览器采用IE内核,多标签,多线程的一个浏览器,带有收藏夹功能。 // //可以查看页面源文件和网页链接状态的功能(可供分析网站的路径),具备// //常用的门户引擎搜索功能。 // //***************************...

    Qt记事本功能齐全,主要实现打开、新建、保存、另存为、查找、居中、字体、颜色、剪切、复制、粘贴等功能

    运用Qt开发工具来实现一个记事本,用户图形界面操作,通过Qt提供的图形库...show_findText()此函数先定义QString类型 findText值,对文本进行扫描,如果文本不能找到找到则提示找不到。 本人也只是一个学生,记得点赞哦!

    抓取RICHEDIT指定文本并滚动到对应位置

    但是文档的定位,如果文档很长那么搜索完成后不会显示到对应的搜索地点,网上很多种方法又是设定光标位置,又是确定文档坐标什么的。太麻烦,我就想有没有简单点的办法,结果还真整出来了,2条语句搞定,比起网上...

    find-text:快速,最少和易于使用的工具,可在多个文件中查找文本

    该模块公开了两个API的findText和findTextInFiles 。 findText import { findText } from 'find-text' /** * findText :: (String, String) =&gt; Promise * * Find the text on the given file. */ findText ( '...

    Microsoft.Office.Interop.Word 操作帮助类

    // /// word转pdf /// /// &lt;param name="sourcePath"&gt;&lt;/param&gt; /// &lt;param name="targetPath"&gt;&lt;/param&gt; ... public void FindAndReplace( Application wordApp, object findText, object replaceText)

    firefox下javascript实现高亮关键词的方法

     IE下有findText及pasteHTML,但是fireFox下就没有!怎么办?查了好多资料,都没有能说出个所以然的,皇天不负有心人,终于让我给搞出来了! 注:我这里不是用正则替换,因为正则替换有它的不足之处! 不知道先前...

    易语言超级编辑框查找选择

    易语言超级编辑框查找选择源码,超级编辑框查找选择,子程序_消息循环,打开查找文本窗口,处理FindText,NewWndLong,IsDialogMessage,RtlMoveMemory_FINDREPLACE2Ptr,RtlMoveMemory_FINDTEXTEX2Ptr,RtlMoveMemory_Ptr2...

    word中如何为金额数字批量添加千分位符号

    可批量对word中的数据添加千分位号 Sub 设置千分位() ... Do While .Execute(findtext:="([0-9])([0-9]{3})([.,])") .Execute replacewith:="\1,\2\3", Replace:=wdReplaceAll Loop End With End Sub

    js正文内容高亮效果的实现方法

    代码如下://高亮显示搜索到的关键字function ... Found = TextRange.findText(Keyword); if (Found) { Count++; } while (Found && Count &gt; 0) { TextRange.pasteHTML(‘&lt;span style=”background

    javascript高亮效果的二种实现方法

    js高亮方法一: 代码如下:[removed] function HighLight(nWord){ if(nWord!=”){ var keyword = document.body.createTextRange(); while(keyword.findText(nWord)){ keyword.pasteHTML(“” + keyword.text + “”)...

    VC如何读取Word文档中的批注内容

    VC读取Word文档中的批注内容 ...Stdafx.h. #import "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\MSO.dll" \ rename("RGB", "_OfficeRGB") ...rename("FindText", "_ScriptFindText") 第二步 .cpp

    光标的帖子总结(Range的使用)

    先说说TextRange 的常用方法 collapse([bStart]) 移动Range的插入点 bStart true(移到开头) false(移到末尾) findText(sText [, iSearchScope] [, iFlags]) 在Range中查找sText iSearchScope 开始位置,负数...

    Next Suite VCL v.6.0.60 D6-XE10.2

    It contains several useful methods (functions and procedures), such as: SaveToXML, LoadFromXML, SaveToINI / LoadFromINI, FindText, BestFitColumn It includes the following components: GRID NEXT Next ...

    Qt Creator 的安装和hello world 程序+其他程序的编写--不是一般的好

    种方法实现了信号和槽函数的关联,第一个按钮我们直接在设计器中实现其关 联;第二个按钮我们自己写了槽函数语句,其实图形的设计与直接写代码效果是 一样的。 这个程序里我们实现了两类窗口打开的方式,一个是自身...

Global site tag (gtag.js) - Google Analytics