Results 1 to 8 of 8

Thread: Like Operator

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Like Operator

    I have a variable z= "1. " = which is any number full stop and space.
    Then If z Like "[1-9]*. " then....

    Sometimes there's a leading Alpha char e.g z = "C1. "


    I expected If z Like "[A-Z][1-9]*. " then.... to work, but it doesn't.

    This should be as fast as possible without too many IFs or evaluations.
    What might be a good solution?

    Thanks.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Like Operator

    The Like-Operator is not RegEx.

    out of my left sleeve:
    I take it you mean digit (not number) --> What about a "0"?
    If it's actually digit, then you look for Length = 3 (1 Digit + 1 period + 1 Space)

    If Len(z)=4 Then z=Mid$(z, 2) 'Has leading Alpha
    If Len(z)=3 Then 'Sanity-Check
    'DoWhatever
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Like Operator

    Thanks for that, didn't think to check for Len.
    Yes it could be "C10."

  4. #4
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Like Operator

    You can stack multiple LIKE checks like this

    If z Like "[0-9]*. " Then
    '--- do something
    ElseIf z Like "[A-Z][0-9]*. " Then
    '--- do the same
    ElseIf z Like "..." Then
    '--- do the same
    Else
    '--- fail
    End If

    cheers,
    </wqw>

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Like Operator

    Quote Originally Posted by AlexanderBB View Post
    Thanks for that, didn't think to check for Len.
    Yes it could be "C10."
    then your If z Like "[1-9]*. " is not going to find that.....

    EDIT: Forget what i said..... it's too early in the morning.....
    In case it's actually a number, sometimes preceeded by an alpha, i revert to my favourite API-Combo of StrSpn/StrCSpn

    Out of curiosity: Is your current check a simple boolean evaluation, or do you need the number for some processing?
    Last edited by Zvoni; Oct 18th, 2021 at 03:52 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6
    Lively Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    126

    Re: Like Operator

    another possibility is

    Code:
    If z Like "*#*.?" Or z Like "*##. " Then
    * = match zero or more char
    # = match a single digit
    ? = match single char

    other very general expressions that should work could be
    Code:
    If z Like "*#*.?" Then
    Code:
    If z Like "*[0-9]*.?" Then
    Code:
    If z Like "*[0-9]??" Then
    Code:
    If z Like "*#*?" Then

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2010
    Posts
    1,462

    Re: Like Operator

    Zvoni I'm doing quite a bit with the result. There is a 3rd condition. This seems to be working

    If (Track Like "[1-9]. *") Or (Track Like "[A-Z][1-9]*. ") Then

    ElseIf Track Like "*)" Then

    End If

    I'm still testing (may need the '0'). I found the space helped with false positives.
    Was hoping to avoid "Or" thinking it might be faster without it.
    Going to try Len next.

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: Like Operator

    Well, if you show how some "real" values for z look like, and what you want to do with it, we might come up with a different solution
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

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



Click Here to Expand Forum to Full Width