473,387 Members | 3,787 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.

ignore case

is there a way to look at a string and ignore the case . i do not want to
modify the string though.

ie. i have a string and want to search for a substring "XYZ" but "XYZ" can
be upper/lower/combination
Nov 16 '05 #1
4 22304
string s = "aBcDXyZeFgHi";
Console.WriteLine (s.IndexOf("xYz", CompareOptions.IgnoreCase);

Thanks,
Michael C., MCDBA

"Sarah" <Sa***@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com...
is there a way to look at a string and ignore the case . i do not want to
modify the string though.

ie. i have a string and want to search for a substring "XYZ" but "XYZ" can
be upper/lower/combination

Nov 16 '05 #2
Hi Sarah,

You can put both strings in the same capitalization before test:

if(name.ToUpper() == "sarah".ToUpper())
{
. . .
}

and you can do it with regular expressions too.

Regards,
Paulo Gomes

"Sarah" wrote:
is there a way to look at a string and ignore the case . i do not want to
modify the string though.

ie. i have a string and want to search for a substring "XYZ" but "XYZ" can
be upper/lower/combination

Nov 16 '05 #3
Michael C <mi******@nospam.org> wrote:
string s = "aBcDXyZeFgHi";
Console.WriteLine (s.IndexOf("xYz", CompareOptions.IgnoreCase);


While using CompareOptions.IgnoreCase is indeed a great way to go (it
saves you having to create two new strings) the above doesn't quite
work. Instead, you need to use something like:

CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;
Console.WriteLine (ci.IndexOf(s, "xYz", CompareOptions.IgnoreCase));

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Good catch. Sorry for the typo - I really need to quit typing when I'm
tired :)

By the way, for the OP - you need to use the System.Globalization namespace
to use CompareInfo.

Thanks,
Michael C., MCDBA

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Michael C <mi******@nospam.org> wrote:
string s = "aBcDXyZeFgHi";
Console.WriteLine (s.IndexOf("xYz", CompareOptions.IgnoreCase);


While using CompareOptions.IgnoreCase is indeed a great way to go (it
saves you having to create two new strings) the above doesn't quite
work. Instead, you need to use something like:

CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;
Console.WriteLine (ci.IndexOf(s, "xYz", CompareOptions.IgnoreCase));

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #5

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

Similar topics

9
by: Thomas Mlynarczyk | last post by:
Which is the simplest way to remove all whitespace from a string? Is there a simpler method than a regex replace? Or how can I tell a regex pattern to ignore all whitespace in my subject string?...
10
by: Nicolas Fleury | last post by:
Hi all, The part of the Python community that doesn't like @decorators needs to unite behind an alternative syntax to propose to Guido. I suggest we use this thread to try to do it. If you...
6
by: CJM | last post by:
I have a page which allows the user to open one of several spreadsheets by streaming the XLS to the client. On my development site, everything appears to work fine. On the live site, it works...
8
by: manning_news | last post by:
Using SQL2000. According to Books Online, the avg aggregrate function ignores null values. ((3+3+3+3+Null)/5) predictably returns Null. Is there a function to ignore the Null entry, adjust the...
2
by: Pierre | last post by:
Hello, I would like to write a regexp that can be either case sensitive or that can ignore the case based on a variable (value would be either 'i' or ''). For instance in the below code the...
4
by: Ron St-Pierre | last post by:
I wish to insert data into a table from a very large text file (from a cron script) using COPY. However if the lName (TEXT), fName(TEXT), workDate(DATE) already exist I don't want to insert data...
4
by: A.M | last post by:
Hi, How can I set the option of RegularExpressionValidator to RegexOptions.IgnoreCase ? Thanks, Alan
0
by: Morten71 | last post by:
I have this regex. in the ValidationExpression property of my dotnet 1.1 RegularExpressionValidator control: ^(?i)(DF)?+$ However, I can't make the ignore case part (?i) work! How should I...
6
by: =?Utf-8?B?YXByMDUyNA==?= | last post by:
I am wondering if there is a devenv switch that will ignore build dependencies that are set in .xxproj files. At the command line I am attempting to build individual projects that I do not want...
2
by: Vinnie123 | last post by:
Is it possible to have mysql ignore the case when performing a search? I am making a user signup script. I want the usernames to be case sensitive (i.e. I do not want to store only lowercase...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.