469,903 Members | 1,501 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

C# equivalent statement for vb "Like" statement?

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

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

Thanks in advance!

Derrick
Nov 16 '05 #1
4 6884
"Derrick" <de*********@excite.com> wrote in news:umhmc1aHEHA.3032
@TK2MSFTNGP09.phx.gbl:
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
Nov 16 '05 #2
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
"Michael Bray" <mb*******************@SkPiAlMl.ctiusa.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Derrick" <de*********@excite.com> wrote in news:umhmc1aHEHA.3032
@TK2MSFTNGP09.phx.gbl:
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

Nov 16 '05 #3
"Derrick" <de*********@excite.com> wrote in
news:#6**************@TK2MSFTNGP12.phx.gbl:
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
Nov 16 '05 #4
Hi Derrick
you can use String.Equals Method which determines whether two String
objects have the same value
string k;
string m;
if (m.equals(k))
you can read more on this link
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemstringclassequalstopic.asp
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Craig Kenisston | last post: by
9 posts views Thread by Drum2001 | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.