转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> C语言系列 >> 正文
[图文]textRange的findText()方法详解         ★★★

textRange的findText()方法详解

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1632 更新时间:2012/12/5 19:54:29
textRange的findText()方法详解

最近在做浏览器的的查找功能,关键字高亮和向上向下查找都差不多了

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

后来到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>

[建站心得]IIS如何绑定中文域名方法详解  [操作系统]用添加任务计划来实现电脑自动关机的方法详解
[学习帮助]快递运费计算方法详解  [电脑技术]在右键新建里添加新建word和excel方法详解
[办公软件]Excel 编号,Excel 自动编号,Excel 编号自动添加方…  [MySql]批处理备份mysql数据库
[MySql]批处理命令BAT备份MySQL数据库  [MySql]用批处理自动备份MySQL数据库方法详解
[MySql]MySQL备份和恢复方法详解  [Web开发]解决“无法在发生错误时创建会话,请检查 PHP 或网…
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台