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 为
相关文档:
这几天在设计阅读其中用到了很多好的技术,,让我们在设计软件的时候方便,,快捷,,美观.也是我们经常用到的一些控件.
所以在这里我会陆续把他分享出来.
这里是在窗体中改变窗体的大小.窗体内部所以控件的大小同比例的改变的一个程序
这些是在标准模块中
'定义 FormOldWidth, FormOldHeight 为全局变量,这样其他模块才能 ......
VC函数是:extern "C" int __declspec(dllexport)PassPortRead(char *InPutData,char OuPutData[255]);
VB声明是:Private Declare Function PassPortRead Lib "PPRead.dll" (ByVal InPutData As String, ByVal OutPutData As String) As Integer
生成的文件能正常运行,并且能生成相应数据,但是在调试时提示"DLL调用约定错 ......
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 ......
转自:http://www.52arm.com/Article_Show.asp?ArticleID=186
作者:weidian ---本站原创 点击数:4721 发表时间:2008-5-7 编辑:sanzang
Winsock控件建立在TCP、UDP协议的基础上,完成与远程计算机的 ......