C# equivalent statement for vb "Like" statement?

  • Thread starter Thread starter Derrick
  • Start date Start date
D

Derrick

Is there a C# "Like" statement for comparing two strings?

if(stringA Like "%diabe%mel%)
do stuff...

Thanks in advance!

Derrick
 
Is there a C# "Like" statement for comparing two strings?

if(stringA Like "%diabe%mel%)
do stuff...

the Regex class (in System.Text.RegularExpressions) can do this for you.
For example:

Regex rgx = new Regex("diabe.*mel");
if (rgx.IsMatch(stringA))
{
// Its a match
}

-mdb
 
Thanks, is it possible to have a regex to searches with "in any order" for
the params passed, in one call without creating all the possible word orders
as seperate regex'es?

With the below example, if a user types "diabe mel", find words that match,
basically, "%diab%mel%" as well as "%mel%diab%"

Thanks again for the help!

Derrick
 
Thanks, is it possible to have a regex to searches with "in any order"
for the params passed, in one call without creating all the possible
word orders as seperate regex'es?

With the below example, if a user types "diabe mel", find words that
match, basically, "%diab%mel%" as well as "%mel%diab%"

Sure... use the '|' operator, meaning this|that. So you could use the
regex "diab.*mel|mel.*diab"

-mdb
 
Back
Top