compare string with a pattern

L

Laura

hi! (and sorry for my low level of english)
i'm trying to compare 2 characters with a determined pattern

the pattern is: "every letter follow followed of every number"

i'm trying to do it with this expresion:

' i select the 2 character to compare
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
If StrComp(Selection.Text, "^$^#", vbTextCompare) Then
' ---
Else
' ---
End If

but the funtion "strComp" doesn´t returns the expected value (always returns
'1')

anybody can help me please??
 
G

Greg Maxey

Try:
Sub Scratchmacro()
Dim myString As String
myString = Selection.Text
MsgBox myString Like "[A-z]#"
End Sub
 
J

Jezebel

Do you really mean [A-z]? -- that's not the same as [A-Za-z] ... [A-z] also
includes the characters between Z and a, namely [\]^_`







Try:
Sub Scratchmacro()
Dim myString As String
myString = Selection.Text
MsgBox myString Like "[A-z]#"
End Sub
 
G

Greg Maxey

That is true. Thanks for pointing out the error.

Do you really mean [A-z]? -- that's not the same as [A-Za-z] ... [A-z] also
includes the characters between Z and a, namely [\]^_`







Try:
Sub Scratchmacro()
Dim myString As String
myString = Selection.Text
MsgBox myString Like "[A-z]#"
End Sub

hi! (and sorry for my low level of english)
i'm trying to compare 2 characters with a determined pattern

the pattern is: "every letter follow followed of every number"

i'm trying to do it with this expresion:

' i select the 2 character to compare
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
If StrComp(Selection.Text, "^$^#", vbTextCompare) Then
' ---
Else
' ---
End If

but the funtion "strComp" doesn´t returns the expected value (always
returns
'1')

anybody can help me please??
 
R

Russ

Laura,
Another thing below.
That is true. Thanks for pointing out the error.

Do you really mean [A-z]? -- that's not the same as [A-Za-z] ... [A-z] also
includes the characters between Z and a, namely [\]^_`







Try:
Sub Scratchmacro()
Dim myString As String
myString = Selection.Text
MsgBox myString Like "[A-z]#"
End Sub

hi! (and sorry for my low level of english)
i'm trying to compare 2 characters with a determined pattern

the pattern is: "every letter follow followed of every number"

i'm trying to do it with this expresion:

' i select the 2 character to compare
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
If StrComp(Selection.Text, "^$^#", vbTextCompare) Then

And from what I read in VBA Help, StrComp() can't use wildcards or Regular
Expression patterns. So you were always comparing to the literal string
^$^#.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top