implementing wildcard match function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrus

    #1

    implementing wildcard match function

    I need to implement vfp function which uses * and ? wildcards:

    static bool Like( cExpression1, cExpression2)

    cExpression1

    Specifies the character expression that Like( ) compares with cExpression2.
    cExpression1 can contain the wildcards such as * and ?. The question mark
    (?) matches any single character in cExpression2 and the asterisk (*)
    matches any number of characters. You can mix any number of wildcards in any
    combination in cExpression1.

    cExpression2
    Specifies the character expression LIKE( ) compares with cExpression1.

    returns true on wildcards match.

    How to implement this ?

    Andrus

  • Tom Dacon

    #2
    Re: implementing wildcard match function

    The simplest and fastest way to do this would be to write a tiny assembly in
    VB, and use the VB Like operator, which does exactly what you want. Put one
    static (Shared in VB) function into it, that takes the two strings and
    returns a Boolean.

    E.g.:

    Public Shared Function VBLike(Byval oneString as String, byval otherString
    as String) as Boolean

    Return oneString Like otherString

    End Function

    I hope this doesn't set off a flame war, and I'm sure that there's also a
    way to do it with Regex, but it's a quick way to get what you want.

    Actually, I'll confess that this response is a little tongue-in-cheek, but
    what can I say :-) Pretty quick someone will be along with the Regex
    equivalent. If I don't see such a response after a while I'll work one up
    for you in C#.

    Tom Dacon
    Dacon Software Consulting

    "Andrus" <kobruleht2@hot .eewrote in message
    news:uE0DjSCIJH A.2408@TK2MSFTN GP04.phx.gbl...
    >I need to implement vfp function which uses * and ? wildcards:
    >
    static bool Like( cExpression1, cExpression2)
    >
    cExpression1
    >
    Specifies the character expression that Like( ) compares with
    cExpression2.
    cExpression1 can contain the wildcards such as * and ?. The question mark
    (?) matches any single character in cExpression2 and the asterisk (*)
    matches any number of characters. You can mix any number of wildcards in
    any
    combination in cExpression1.
    >
    cExpression2
    Specifies the character expression LIKE( ) compares with cExpression1.
    >
    returns true on wildcards match.
    >
    How to implement this ?
    >
    Andrus
    >

    Comment

    • Andrus

      #3
      Re: implementing wildcard match function

      Tom,
      Public Shared Function VBLike(Byval oneString as String, byval otherString
      as String) as Boolean
      >
      Return oneString Like otherString
      >
      End Function
      Thank you.
      I have C# 2008 Express. It does not allow to program in VB.
      I think there must be some method in some net dll whose call in generated by
      VB compiler for like operator .

      Do you know what it this method name so I can call it from C# code ?
      Or is there vb -c# converter which converts this code?

      Andrus.

      Comment

      • Tom Dacon

        #4
        Re: implementing wildcard match function

        Andrus, here is the method name to use when you're calling from C#:

        Microsoft.Visua lBasic.Compiler Services.Operat ors.LikeString

        However if what you're running is C# 2008 Express you may not actually have
        the VB assemblies at all. Cross your fingers and go to the references dialog
        and see what you find.

        Otherwise, I'd pursue a solution with the Regex class in
        System.Text.Reg ularExpressions . Try these sites to start:

        At Regular-Expressions.info you will find a wide range of in-depth information about a powerful search pattern language called regular expressions.




        One of those sites has a Regex tester that you can use to try out your
        attempts.

        Regex syntax is ugly and finicky, but very powerful. It's a "language" only
        a programmer could love, and only a few do. I suspect that far less than one
        percent of C# programmers are even competent with Regex expressions, let
        alone fluent. However the rules you need to implement are simple, so perhaps
        you might find your way to a suitable Regex expression without too much
        difficulty.

        Good luck,
        Tom Dacon

        "Andrus" <kobruleht2@hot .eewrote in message
        news:%23Mex36HI JHA.3496@TK2MSF TNGP05.phx.gbl. ..
        Tom,
        >
        >Public Shared Function VBLike(Byval oneString as String, byval
        >otherString as String) as Boolean
        >>
        > Return oneString Like otherString
        >>
        >End Function
        >
        Thank you.
        I have C# 2008 Express. It does not allow to program in VB.
        I think there must be some method in some net dll whose call in generated
        by VB compiler for like operator .
        >
        Do you know what it this method name so I can call it from C# code ?
        Or is there vb -c# converter which converts this code?
        >
        Andrus.
        >

        Comment

        • Tom Dacon

          #5
          Re: implementing wildcard match function

          Andrus, here's a link to a discussion of implementing the VB Like
          functionality with Regex. It may be useful to you.



          Tom Dacon
          Dacon Software Consulting

          "Andrus" <kobruleht2@hot .eewrote in message
          news:%23Mex36HI JHA.3496@TK2MSF TNGP05.phx.gbl. ..
          Tom,
          >
          >Public Shared Function VBLike(Byval oneString as String, byval
          >otherString as String) as Boolean
          >>
          > Return oneString Like otherString
          >>
          >End Function
          >
          Thank you.
          I have C# 2008 Express. It does not allow to program in VB.
          I think there must be some method in some net dll whose call in generated
          by VB compiler for like operator .
          >
          Do you know what it this method name so I can call it from C# code ?
          Or is there vb -c# converter which converts this code?
          >
          Andrus.
          >

          Comment

          • Andrus

            #6
            Re: implementing wildcard match function

            Andrus, here's a link to a discussion of implementing the VB Like
            functionality with Regex. It may be useful to you.
            >
            http://groups.google.com/group/micro...ba3e39a6c2711f
            THank you.
            This referest to internal method not recommended for use from applications.

            How to implement this in pure C# ?

            Andrus.

            Comment

            • Tom Dacon

              #7
              Re: implementing wildcard match function

              Andrus, one of the messages in the discussion contains a link to a web site
              with code that does it. The latter part of the message thread discusses
              changes and extensions to the supplied code.

              Good luck,
              Tom Dacon
              Dacon Software Consulting

              "Andrus" <kobruleht2@hot .eewrote in message
              news:eBUovAYIJH A.508@TK2MSFTNG P05.phx.gbl...
              >Andrus, here's a link to a discussion of implementing the VB Like
              >functionalit y with Regex. It may be useful to you.
              >>
              >http://groups.google.com/group/micro...ba3e39a6c2711f
              >
              THank you.
              This referest to internal method not recommended for use from
              applications.
              >
              How to implement this in pure C# ?
              >
              Andrus.

              Comment

              Working...