tw_chase
asked on
Instr Like Function in Visual Basic 6
I need to know how to get the starting position in a string using masks you use in LIKE functions. Let me clarify.
Say I have a string like "ABCDEFG123MNOPQ"
I want the starting position where the string is like ###. I don't want any Mid functions because that could take a long time to scan huge strings position by position. Does VB6 have a built in function or is there another way?
Instr("ABCDEFG123MNOPQ","1 23") will return my starting postion
"ABCDEFG123MNOPQ" LIKE "*###*" will return if that mask combination exists.
I need the combination of both.
Thanks in advance.
Say I have a string like "ABCDEFG123MNOPQ"
I want the starting position where the string is like ###. I don't want any Mid functions because that could take a long time to scan huge strings position by position. Does VB6 have a built in function or is there another way?
Instr("ABCDEFG123MNOPQ","1
"ABCDEFG123MNOPQ" LIKE "*###*" will return if that mask combination exists.
I need the combination of both.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sub tw_chase()
Dim RegEx As Object, RegM As Object, tempStr As String, tempStr2 As String
Set RegEx = CreateObject("vbscript.reg
RegEx.Pattern = "\d{3}"
tempStr = "ABCDEFG123MNOPQ"
tempStr2 = "as2lkasdfo34klalsd872alsd
If RegEx.Test(tempStr) Then
Set RegM = RegEx.Execute(tempStr).Ite
MsgBox "Original string: " & tempStr & vbCrLf & _
"""" & RegM & """ found at position " & RegM.FirstIndex + 1
End If
If RegEx.Test(tempStr2) Then
Set RegM = RegEx.Execute(tempStr2).It
MsgBox "Original string: " & tempStr2 & vbCrLf & _
"""" & RegM & """ found at position " & RegM.FirstIndex + 1
End If
Set RegEx = Nothing
Set RegM = Nothing
End Sub
Matt