By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,818 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,818 IT Pros & Developers. It's quick & easy.

C# equivalent statement for vb "Like" statement?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
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.