Like Operator

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

    #1

    Like Operator

    In the old Visual Basic I could do something like this

    myCheck = "aBBBa" Like "a*a"

    The return value would be true. Is there a way for comparing strings in C#
    were I can use wild characters like * etc?


  • Chris R. Timmons

    #2
    Re: Like Operator

    "Rene" <nospam@nospam. com> wrote in
    news:u7bxszXhDH A.4024@TK2MSFTN GP11.phx.gbl:
    [color=blue]
    > In the old Visual Basic I could do something like this
    >
    > myCheck = "aBBBa" Like "a*a"
    >
    > The return value would be true. Is there a way for comparing
    > strings in C# were I can use wild characters like * etc?[/color]

    The .Net framework provides regular expressions:


    using System.Text.Reg ularExpressions ;
    ...
    bool myCheck = Regex.IsMatch(" aBBBa", "^a.*a$");


    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.

    Comment

    • Rene

      #3
      Re: Like Operator

      Your pattern string has a "^" a "." a "*" and a "$". Could you please tell
      me what all this symbols are for? I recognize the reason for the "*" but I
      have no idea what the others are there for! I didn't find this info in the
      documentation.

      Thank you.

      "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in message
      news:Xns9404263 A5716crtimmonsc rtimmonsin@207. 46.248.16...[color=blue]
      > "Rene" <nospam@nospam. com> wrote in
      > news:u7bxszXhDH A.4024@TK2MSFTN GP11.phx.gbl:
      >[color=green]
      > > In the old Visual Basic I could do something like this
      > >
      > > myCheck = "aBBBa" Like "a*a"
      > >
      > > The return value would be true. Is there a way for comparing
      > > strings in C# were I can use wild characters like * etc?[/color]
      >
      > The .Net framework provides regular expressions:
      >
      >
      > using System.Text.Reg ularExpressions ;
      > ...
      > bool myCheck = Regex.IsMatch(" aBBBa", "^a.*a$");
      >
      >
      > Hope this helps.
      >
      > Chris.
      > -------------
      > C.R. Timmons Consulting, Inc.
      > http://www.crtimmonsinc.com/[/color]


      Comment

      • Bret Mulvey

        #4
        Re: Like Operator

        "^" means the beginning of the string. If you left this out, it would match
        things like XYZaBBBa

        "." means any character and ".*" means any number (zero or more) of any
        character

        "$" means the end of the string. If you left this out, it would match things
        like aBBBaXYZ


        "Rene" <nospam@nospam. com> wrote in message
        news:ejdp3aYhDH A.352@tk2msftng p13.phx.gbl...[color=blue]
        > Your pattern string has a "^" a "." a "*" and a "$". Could you please tell
        > me what all this symbols are for? I recognize the reason for the "*" but I
        > have no idea what the others are there for! I didn't find this info in the
        > documentation.
        >
        > Thank you.
        >
        > "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in message
        > news:Xns9404263 A5716crtimmonsc rtimmonsin@207. 46.248.16...[color=green]
        > > "Rene" <nospam@nospam. com> wrote in
        > > news:u7bxszXhDH A.4024@TK2MSFTN GP11.phx.gbl:
        > >[color=darkred]
        > > > In the old Visual Basic I could do something like this
        > > >
        > > > myCheck = "aBBBa" Like "a*a"
        > > >
        > > > The return value would be true. Is there a way for comparing
        > > > strings in C# were I can use wild characters like * etc?[/color]
        > >
        > > The .Net framework provides regular expressions:
        > >
        > >
        > > using System.Text.Reg ularExpressions ;
        > > ...
        > > bool myCheck = Regex.IsMatch(" aBBBa", "^a.*a$");
        > >
        > >
        > > Hope this helps.
        > >
        > > Chris.
        > > -------------
        > > C.R. Timmons Consulting, Inc.
        > > http://www.crtimmonsinc.com/[/color]
        >
        >[/color]


        Comment

        • Rene

          #5
          Re: Like Operator

          Thank you, that really helped.

          Could you please tell me where can I find this information (web link or
          something similar) so that I can take a closer look and see what else I can
          learn about comparing string?

          Thank you.



          "Bret Mulvey" <bretm@microsof t.nospam0000.co m> wrote in message
          news:1Uvdb.6118 23$uu5.99847@sc crnsc04...[color=blue]
          > "^" means the beginning of the string. If you left this out, it would[/color]
          match[color=blue]
          > things like XYZaBBBa
          >
          > "." means any character and ".*" means any number (zero or more) of any
          > character
          >
          > "$" means the end of the string. If you left this out, it would match[/color]
          things[color=blue]
          > like aBBBaXYZ
          >
          >
          > "Rene" <nospam@nospam. com> wrote in message
          > news:ejdp3aYhDH A.352@tk2msftng p13.phx.gbl...[color=green]
          > > Your pattern string has a "^" a "." a "*" and a "$". Could you please[/color][/color]
          tell[color=blue][color=green]
          > > me what all this symbols are for? I recognize the reason for the "*" but[/color][/color]
          I[color=blue][color=green]
          > > have no idea what the others are there for! I didn't find this info in[/color][/color]
          the[color=blue][color=green]
          > > documentation.
          > >
          > > Thank you.
          > >
          > > "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in[/color][/color]
          message[color=blue][color=green]
          > > news:Xns9404263 A5716crtimmonsc rtimmonsin@207. 46.248.16...[color=darkred]
          > > > "Rene" <nospam@nospam. com> wrote in
          > > > news:u7bxszXhDH A.4024@TK2MSFTN GP11.phx.gbl:
          > > >
          > > > > In the old Visual Basic I could do something like this
          > > > >
          > > > > myCheck = "aBBBa" Like "a*a"
          > > > >
          > > > > The return value would be true. Is there a way for comparing
          > > > > strings in C# were I can use wild characters like * etc?
          > > >
          > > > The .Net framework provides regular expressions:
          > > >
          > > >
          > > > using System.Text.Reg ularExpressions ;
          > > > ...
          > > > bool myCheck = Regex.IsMatch(" aBBBa", "^a.*a$");
          > > >
          > > >
          > > > Hope this helps.
          > > >
          > > > Chris.
          > > > -------------
          > > > C.R. Timmons Consulting, Inc.
          > > > http://www.crtimmonsinc.com/[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Jon Skeet

            #6
            Re: Like Operator

            Rene <nospam@nospam. com> wrote:[color=blue]
            > Thank you, that really helped.
            >
            > Could you please tell me where can I find this information (web link or
            > something similar) so that I can take a closer look and see what else I can
            > learn about comparing string?[/color]

            Look up "regular expressions" in the MSDN, and you should find a lot of
            information.

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • Rudy Velthuis

              #7
              Re: Like Operator

              Rene wrote:
              [color=blue]
              > Your pattern string has a "^" a "." a "*" and a "$". Could you please
              > tell me what all this symbols are for? I recognize the reason for the
              > "*" but I have no idea what the others are there for! I didn't find
              > this info in the documentation.[/color]

              Look for "regular expressions" in the index of the .NET docs. You'll find
              a huge range of topics about it.
              --
              Rudy Velthuis

              "Before C++ we had to code all of our bugs by hand; now we inherit
              them." -- unknown

              Comment

              • Bret Mulvey

                #8
                Re: Like Operator

                MSDN has documentatioin for this at
                http://msdn.microsoft.com/library/en...ularexpression
                slanguageelemen ts.asp


                "Rene" <nospam@nospam. com> wrote in message
                news:eRHlBhZhDH A.1668@TK2MSFTN GP12.phx.gbl...[color=blue]
                > Thank you, that really helped.
                >
                > Could you please tell me where can I find this information (web link or
                > something similar) so that I can take a closer look and see what else I[/color]
                can[color=blue]
                > learn about comparing string?
                >
                > Thank you.
                >
                >
                >
                > "Bret Mulvey" <bretm@microsof t.nospam0000.co m> wrote in message
                > news:1Uvdb.6118 23$uu5.99847@sc crnsc04...[color=green]
                > > "^" means the beginning of the string. If you left this out, it would[/color]
                > match[color=green]
                > > things like XYZaBBBa
                > >
                > > "." means any character and ".*" means any number (zero or more) of any
                > > character
                > >
                > > "$" means the end of the string. If you left this out, it would match[/color]
                > things[color=green]
                > > like aBBBaXYZ
                > >
                > >
                > > "Rene" <nospam@nospam. com> wrote in message
                > > news:ejdp3aYhDH A.352@tk2msftng p13.phx.gbl...[color=darkred]
                > > > Your pattern string has a "^" a "." a "*" and a "$". Could you please[/color][/color]
                > tell[color=green][color=darkred]
                > > > me what all this symbols are for? I recognize the reason for the "*"[/color][/color][/color]
                but[color=blue]
                > I[color=green][color=darkred]
                > > > have no idea what the others are there for! I didn't find this info in[/color][/color]
                > the[color=green][color=darkred]
                > > > documentation.
                > > >
                > > > Thank you.
                > > >
                > > > "Chris R. Timmons" <crtimmons@X_NO SPAM_Xcrtimmons inc.com> wrote in[/color][/color]
                > message[color=green][color=darkred]
                > > > news:Xns9404263 A5716crtimmonsc rtimmonsin@207. 46.248.16...
                > > > > "Rene" <nospam@nospam. com> wrote in
                > > > > news:u7bxszXhDH A.4024@TK2MSFTN GP11.phx.gbl:
                > > > >
                > > > > > In the old Visual Basic I could do something like this
                > > > > >
                > > > > > myCheck = "aBBBa" Like "a*a"
                > > > > >
                > > > > > The return value would be true. Is there a way for comparing
                > > > > > strings in C# were I can use wild characters like * etc?
                > > > >
                > > > > The .Net framework provides regular expressions:
                > > > >
                > > > >
                > > > > using System.Text.Reg ularExpressions ;
                > > > > ...
                > > > > bool myCheck = Regex.IsMatch(" aBBBa", "^a.*a$");
                > > > >
                > > > >
                > > > > Hope this helps.
                > > > >
                > > > > Chris.
                > > > > -------------
                > > > > C.R. Timmons Consulting, Inc.
                > > > > http://www.crtimmonsinc.com/
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                Working...