Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    171
    Thanks
    3
    Thanked 0 Times in 0 Posts

    How to use the 'Like' operator to match parentheses (brackets)

    Hi all,

    I can't get the 'Like' operator to match parentheses (brackets). I want to match a pair of parentheses with a digit between them. The following is not succeeding"

    Code:
    Dim Txt As String
    Dim MyCheck As Boolean
    
    Txt = "nk2xen - configurator(1)"
    MyCheck = Txt Like "(#)"
    MyCheck is return with false.

    I tried escaping the ( by using a backslash...

    Code:
      \(
    and also by using an extra ( ...

    Code:
      ((
    But neither work.

    Ideas, anybody?

    TIA

    -avraham

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,498
    Thanks
    212
    Thanked 852 Times in 784 Posts
    Avraham,

    You want it this way: MyCheck = Txt Like "*(#)"
    The * means you don't care how many characters precede the pattern.
    If the pattern was in the middle of the string you would need an asterisk on each side of the pattern.

    Microsoft Help on Like.
    Last edited by RetiredGeek; 2011-10-10 at 19:54.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  3. The Following User Says Thank You to RetiredGeek For This Useful Post:

    amakeler (2011-10-11)

  4. #3
    2 Star Lounger
    Join Date
    Dec 2007
    Posts
    171
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Good grief... how did I forgot that ...
    Serves me right for trying to start writing a whole new mechanism at 1:00 AM...

    I see I also copied original text instead of fabricating an example... that's how tired I was.

    Yep - it works now.

    Great thanks!

    -avraham



    Quote Originally Posted by RetiredGeek View Post
    Avraham,

    You want it this way: MyCheck = Txt Like "*(#)"
    The * means you don't care how many characters precede the pattern.
    If the pattern was in the middle of the string you would need an asterisk on each side of the pattern.

    Microsoft Help on Like.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •