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","123") will return my starting postion

"ABCDEFG123MNOPQ" LIKE "*###*" will return if that mask combination exists.

I need the combination of both.

Thanks in advance.
tw_chaseAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
mvidasCommented:
I agree with angel, regular expressions would definately be the way to go, he deserves the majority if not all of the points for it.  If it helps, heres an example for you:

Sub tw_chase()
 Dim RegEx As Object, RegM As Object, tempStr As String, tempStr2 As String
 Set RegEx = CreateObject("vbscript.regexp")
 RegEx.Pattern = "\d{3}"
 tempStr = "ABCDEFG123MNOPQ"
 tempStr2 = "as2lkasdfo34klalsd872alsd"
 If RegEx.Test(tempStr) Then
  Set RegM = RegEx.Execute(tempStr).Item(0)
  MsgBox "Original string: " & tempStr & vbCrLf & _
         """" & RegM & """ found at position " & RegM.FirstIndex + 1
 End If
 If RegEx.Test(tempStr2) Then
  Set RegM = RegEx.Execute(tempStr2).Item(0)
  MsgBox "Original string: " & tempStr2 & vbCrLf & _
         """" & RegM & """ found at position " & RegM.FirstIndex + 1
 End If
 Set RegEx = Nothing
 Set RegM = Nothing
End Sub

Matt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.