教程中国
PHOTOSHOP CS9.0中文版 MAYA 8.5 FOR WINDOWS Corel Painter v9.0 Flash MX2004 中文版 Illustrator cs2 中文版
VC++6.0含sp6 中英文版 VB6.0 +sp6 简体中文版 Borland Delphi 7汉化版 MSDN for vb6.0中文版 Visual Studio 2005简体
教程中国下属 文件存储共享专家BIBIDU.COM 提供大型软件,教材,源码,电影,音乐,图书等下载 更多精品请点此进入
  您目前所在位置: 教程中国 >> 编程基地 >> VB >> Use regular expressions for VB wildcard string extractions RSS订阅
Use regular expressions for VB wildcard string extractions
教程(视频,书籍)下载:  ASP.NET AutoCAD 数据库 C# ASP java photoshop 网页设计 delphi 3dmax Flash C++ VB 张孝祥 实例   更多请进入BIBIDU搜索
IT搜索引擎   
Use regular expressions for VB wildcard string extractions

While VB provides several ways to perform string manipulations
and searches, it doesn注释:t always provide the best wildcard search
options. To that end, try using regular expressions, introduced
in VBScript 5.0+, but available for use in VB projects.

Regular expressions let you quickly and concisely search for patterns
within strings, and in most cases perform an action on them. In
its basic form, a regular expression consists of a single or series
of strings, literal or representative. You can then match this
template against a second string or number (as a string). For example,
the literal pattern 注释:abc注释: as a regular expression would find a
match in 注释:dabcef注释:, 注释:abcdef注释: or 注释:defabc注释:. As you might expect, you
can also use a host of special metacharacters to further refine
a regular expression. Visit Microsoft注释:s VBScript documentation
Web site (msdn.microsoft.com/scripting) and then look up the RegExp
in the VBScript Keyword Documentation section to learn more specifics
about these patterns.

To give you a taste of what regular expressions can do, however,
suppose your project accepted input in the following format:

A1234B4567

Under the program注释:s guidelines, there can be any number of digits
between the A and the B, as well as after the B. In your code,
you want to extract the string, including all digits after the
B. To accomplish this task, after setting a reference to the Microsoft
VBScript Regular Expressions 1.0 library, you could use code similar
to:

Private Sub Form_Load()
Dim reg As New RegExp
Dim strTest As String
Dim regPattern As String
Dim Matches As MatchCollection
Dim mtch As Match

Dim blnFound As Boolean

strTest = "A1234B4567"
regPattern = "B\d+$"

With reg
    .Pattern = regPattern
    MsgBox .Test(strTest)
    Set Matches = .Execute(strTest)
    
    For Each mtch In Matches
        MsgBox mtch.Value
    Next mtch
End With
Set reg = Nothing

End Sub

For more information and a tutorial on how to use regular expressions
to validate user data entry, read Inside Microsoft Visual Basic注释:s
August 2001 article "Provide field validation with regular expressions"
(www.elementkjournals.com/ivb/0108/ivb0181.htm).

来源:upschool.cn
作者:
关键字:Use,regular,for,VB,wildcard,string
发表日期:2006-12-20 19:57:26

网页显示有限 阅读全文请下载本文完整版WORD文档

上一篇:MySQL中文模糊检索问题的解决方法   下一篇:用VB轻松打开MS Word文档


2009-1-10 9:54:10
本文的相类似文章
  • VB简单计算函数的编写过程
  • VB 快速读取TextBox第N行的数据
  • VB编程的好帮手--资源文件
  • VB 利用API创建文件目录
  • VB的API编程精粹(一)
  • VB的API编程精粹(二)
  • API函数快速入门--怎样在VB中声明和使用API函数
  • VB的编译优化
  • VB中用Multimedia MCI控件开发多媒体应用
  • 认识VB的扩展名
  • 在学习中进步 在进步中成长 教程中国相随您的成长之路
    华腾联合科技股份有限公司版权所有
    广告联系:Rosibo@163.com