473,387 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 7218
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Adam Short | last post by:
I've never needed it before but now I do! Does anyone know if you are able to perform a NOT Like search using Classic ASP ADO? i.e. myData.Filter = "Ref NOT LIKE '*1234*'" by the way this...
9
by: Peter | last post by:
My problem is the last bit of coding below, the like statement does not work. what I have is a product options field and in it is stored characters i.e. "avcy" etc what the query does is...
5
by: TD | last post by:
I created a query in Access 2000 that runs perfectly. I then copied the "sql" version of the same query and set it equal the variable "sql" in the code below. When I run the code below I get an...
2
by: Big John | last post by:
in Access 2003 I am trying to get sql query to run using a field as input, but I want to input into the field a value that uses the "like" operator to find any value that starts with the value...
3
by: Derrick | last post by:
Is there a C# "Like" statement for comparing two strings? if(stringA Like "%diabe%mel%) do stuff... Thanks in advance! Derrick
1
by: Craig Kenisston | last post by:
Hi, I need to write a function that should behave like the SQL's "like" operator on a list of words. I was wondering if I can use Regex directly to do this job. But I've been reading about...
9
by: Drum2001 | last post by:
Hello All! I am using the following code during an On Click event for a button. It works properly to create a query for a report: Private Sub Command14_Click() If IsNull(Me.Text30) Then ' No...
1
by: unamas | last post by:
hi, Good day! Anyone generous enough to help me with this query. Anyway, I have a random acount number of 1, 2, 3, 4, 5 and i wanna get the results after this number in a table. Select...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.