VB中字符串匹配的多种方式
这段时间在移植项目的过程中,起初我想判断一个字符串中是否存在某字符(串),直接的使用方法是用instr(start,string1,string2,VB compare),但经过分析在VB中可以只用一下方法来判断!
1.常用的INStr方法
Function InStr([Start], [String1], [String2], [Compare As VbCompareMethod = vbBinaryCompare])
VBA.Strings 的成员
返回在另一字符串中第一次出现某一字符串的位置
判断string1中从start开始的位置第一次出现string2的位置
2.使用正则表达式
在VB中需要引入Library VBScript_RegExp_55
位置在C:\WINDOWS\System32\vbscript.dll\3
Microsoft VBScript Regular Expressions 5.5
当然,你可以直接在项目中引用,使用方法如下:
Dim ResultString As String
Dim myRegExp As RegExp
Dim resultCollection As MatchCollection
Const pattern As String = "^\s*Dim\s+([\w|,|\s]+)(?:\s+As\s+Recordset)"
Public Function executes(SubjectString As String, result As MatchCollection)
Set myRegExp = New RegExp
myRegExp.MultiLine = True
myRegExp.Global = True
myRegExp.pattern = pattern
Set result = myRegExp.Execute(Trim(SubjectString))
End Function
3.第三种是比较特别的方法,是采用if string like [parttern],即string需要满足parttern中的模式,才会返回true,其具体定义如下:
语法
result = string Like pattern
Like 运算符的语法具有以下几个部分:
部分 描述
result 必需的;任何数值变量。
string 必需的;任何字符串表达式。
pattern 必需的;任何字符串表达式,遵循“说明”中的模式匹配约定。
说明
如果 string 与 pattern 匹配,则 result 为
相关文档:
接着外挂教程 VB 从零开始编外挂
需要VBAPI函数:
FindWindow←寻找窗口列表中第一个符合指定条件的顶级窗口
GetWindowThreadProcessId←获取与指定窗口关联在一起的一个进程和线程标识符
--------------------------------------------------------------------------------------------------------------- ......
Introduction
This article is about passing data between VB.NET/C# WinForms and JavaScript.
Before reading further, let me warn you that this article is not about ASP.NET. Concepts covered in the article are applied to Desktop applications.
Background
I was working on a project which required dat ......
当MDB 文件加了密码,直接由 Access 打印MDB文件时,会出现密码对话框,询问密码。但是若要由 VB 程序中打印,必須更改 VB程序中打开MDB文件的指令,否则会出现错误信息!以下针对各种情况,分別加以说明:
1、 使用 D ......
※==================================================================
※本连载文章说明:
※1、连载首发于《软件报》(http://www.sweek.com)2006年21期(2006年5月22日);
※2、此次网上连载采用的是原稿件结构,内容与《软件报》发表略有不同;
※3、谢绝除《软件报》及其相关刊物之外的传统媒体部分或全部转载 ......
Option Explicit
Private rsMain As ADODB.Recordset
Private rsTerm As ADODB.Recordset
Private strSql As String
Private Sub cmdAbout_Click()
frmAbout.Show
End Sub
Private Sub cmdAddObject_Click() '程序段
......