473,385 Members | 1,492 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,385 software developers and data experts.

Like Operator in C#

I want to check for a conditon as follows:

if ( name Like "sa*")

So, I need to use this * as a wild card and the above statement should return all those names which starts with sa.

I know that VB Like operator will do this one.
I want to know whether we have any similar one in C#?

Nov 15 '05 #1
6 53252
There is no like operator in C#, you will have to use regular expressions.

"Saradhi" <up*******@inooga.com> wrote in message
news:%2********************@TK2MSFTNGP09.phx.gbl.. .
I want to check for a conditon as follows:

if ( name Like "sa*")

So, I need to use this * as a wild card and the above statement should
return all those names which starts with sa.

I know that VB Like operator will do this one.
I want to know whether we have any similar one in C#?

Nov 15 '05 #2
Can you use StartsWith ?

string s = "Sam";
if ( s.StartsWith("Sa") )
//do something.

--
William Stacey, MVP

"Saradhi" <up*******@inooga.com> wrote in message news:#k**************@TK2MSFTNGP09.phx.gbl...
I want to check for a conditon as follows:

if ( name Like "sa*")

So, I need to use this * as a wild card and the above statement should return all those names which starts with sa.

I know that VB Like operator will do this one.
I want to know whether we have any similar one in C#?

Nov 15 '05 #3
"Saradhi" <up*******@inooga.com> wrote in
news:#k**************@TK2MSFTNGP09.phx.gbl:
I want to check for a conditon as follows:

if ( name Like "sa*")

So, I need to use this * as a wild card and the above statement should
return all those names which starts with sa.


C# doesnt have one - but in this simple case just compare the first two
characters.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #4
its just an example.

there can be any number of conditons like

name like '*sa*'
name like 'sa*'
name like 'sa%'

Bottom line is I need to implement the Wild Cards in the comparision

"William Stacey [MVP]" <st***********@mvps.org> wrote in message news:uf****************@tk2msftngp13.phx.gbl...
Can you use StartsWith ?

string s = "Sam";
if ( s.StartsWith("Sa") )
//do something.

--
William Stacey, MVP

"Saradhi" <up*******@inooga.com> wrote in message news:#k**************@TK2MSFTNGP09.phx.gbl...
I want to check for a conditon as follows:

if ( name Like "sa*")

So, I need to use this * as a wild card and the above statement should return all those names which starts with sa.

I know that VB Like operator will do this one.
I want to know whether we have any similar one in C#?
Nov 15 '05 #5

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:us****************@tk2msftngp13.phx.gbl...
There is no like operator in C#, you will have to use regular expressions.
"Saradhi" <up*******@inooga.com> wrote in message
news:%2********************@TK2MSFTNGP09.phx.gbl.. .
I want to check for a conditon as follows:
if ( name Like "sa*")


This is the answer you are looking for Saradhi.
Daniel gave you a fine piece of advice. Use regular expressions.

- Michael S
Nov 15 '05 #6
"Saradhi" <up*******@inooga.com> wrote in message news:<#k**************@TK2MSFTNGP09.phx.gbl>...
I want to check for a conditon as follows:

if ( name Like "sa*")

So, I need to use this * as a wild card and the above statement should
return all those names which starts with sa.

I know that VB Like operator will do this one.
I want to know whether we have any similar one in C#?

--


Hi,
in case you don't want to use VB specific things regular expressions
can be used, imo regular expressions are essential, I use it regularly

if (System.Text.RegularExpressions.Regex.Match("samsg sgs","sa.*").Success)
MessageBox.Show("");

Frank
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vlad | last post by:
I operate with 2 tables: tbLocations and tbDepartments. Both have a column named Town. tbLocations.Town looks like long unique list of different towns world wide: Copenhagen Madrid Roma
0
by: Alvar Freude | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, the following I posted already on pgsql-bugs -- perhaps someone has a good workaround or fix or can say me that I'm wrong? There seems to...
10
by: Steve Jorgensen | last post by:
Microsoft acknowledges a bug with this, but the bug is worse than they say. It turns out that if you use the Like operator without a wildcard on a snapshot type recordset, all sorts of wierd,...
4
by: Regnab | last post by:
I've got a number of 'Lots' of cattle - ie 40A, 372A, W123 etc. The letter in the Lot number indicates where the animal is traceable or not. The animal's Lot number, along with its individual...
2
by: Ed Brown | last post by:
I'm working on a VB.Net application that needs to do quite a bit of string pattern matching, and am having problems using the "LIKE" operator to match the same string twice in the pattern. For...
3
by: Michael Roppel | last post by:
If I do a SELECT .... WHERE DTEXT LIKE '%Findit%' on an iSeries, I won't get records with 'findit' because the LIKE Operator is case sensitive. Is there a way to do a non case sensitive selection...
2
by: neeraj | last post by:
Hi, all Could anny one give me help how can I use like operator with these data types "integer , datetime or boolean" in DataView.RowFilter Actually when I try to get the data from dataview...
2
by: Deepa Jeevagan | last post by:
Hi, The application I am currently working on is developed in Oracle 8i. I have a table which has a nullable numeric column say CustNo. This column has an index defined on it and oracle uses...
7
by: bytesshalini | last post by:
Hi friends... can anybody tell me how to use the like operator to fetch only digits... for eg: i have a col x whose value is 7890. i want to use like operator in select stmt to fetch the value of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.