473,320 Members | 1,978 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,320 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 7209
"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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.