Like Operator

  • Thread starter Thread starter Rene
  • Start date Start date
R

Rene

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?
 
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.RegularExpressions;
...
bool myCheck = Regex.IsMatch("aBBBa", "^a.*a$");


Hope this helps.

Chris.
 
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.
 
"^" 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 said:
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.
 
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 said:
"^" 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 said:
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?

Look up "regular expressions" in the MSDN, and you should find a lot of
information.
 
Rene said:
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.

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