Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

compare string with a pattern

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Laura - 05 Sep 2006 12:52 GMT
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??
Greg Maxey - 05 Sep 2006 13:17 GMT
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
[quoted text clipped - 15 lines]
>
> anybody can help me please??
Jezebel - 05 Sep 2006 14:10 GMT
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

Laura wrote:
> hi! (and sorry for my low level of english)
> i'm trying to compare 2 characters with a determined pattern
[quoted text clipped - 16 lines]
>
> anybody can help me please??
Greg Maxey - 05 Sep 2006 14:24 GMT
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 [\]^_`
[quoted text clipped - 27 lines]
> >
> > anybody can help me please??
Russ - 10 Sep 2006 05:27 GMT
Laura,
Another thing below.

> That is true. Thanks for pointing out the error.
>
[quoted text clipped - 19 lines]
>>> 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
^$^#.

>>>     ' ---
>>> Else
[quoted text clipped - 6 lines]
>>>
>>> anybody can help me please??

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.