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

c#.NET Checking for an element in an array case insensitive

rhitam30111985
112 100+
Hi all ,


I found a way to check for an element in a c# array here :

http://www.dotnettoad.com/index.php?....Contains.html

But this is case sensitive search. Is there a way to do the same thing by ignoring case ?


Regards ,

Rhitam
Apr 14 '09 #1
3 8898
tlhintoq
3,525 Expert 2GB
I'm lazy... I just do all my comparrisons using the .ToLower() method

Expand|Select|Wrap|Line Numbers
  1. String bob = "This is a Mixed Case String";
  2. if (bob.ToLower() contains "mixed")
  3. {
  4.      // Jump for joy
  5. }
Apr 14 '09 #2
kurtzky
26
C# is case-sensitive so you have to make sure that the value you are comparing should be the same, that means you need to use either to lower or to upper, depending on the value you want to compare.
Apr 15 '09 #3
Expand|Select|Wrap|Line Numbers
  1.         public string[] Contains(IEnumerable<string> array, string val)
  2.         {
  3.             return (new List<string>(array)).FindAll(s => s.ToLower() == val.ToLower()).ToArray();
  4.         }
Or

Expand|Select|Wrap|Line Numbers
  1.         public string Contains(IEnumerable<string> array, string val)
  2.         {
  3.             return (new List<string>(array)).Find(s => s.ToLower() == val.ToLower());
  4.         }
That's what I use at least. :)
Apr 16 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: noah | last post by:
Can anyone think of a way to make array keys case insensitive? An option on any recent PHP would be to convert all array keys to lowercase using the standard array_change_key_case() function. As...
5
by: Madjid Nasiri | last post by:
Hi, I am basic in oracle. My Old programs write with Delphi and Databases: Access, Paradox, MySQL, Microsoft SQL. I write my code (SQL code) case-insensitivae, but now i need use oracle database....
1
by: D. Alvarado | last post by:
Hello, I'm sure this is a pretty easy question, but how would I indnicate in my XML schema that I wanted to make attribute name comparisons case insensitive? For example, is I had an element ...
12
by: Relaxin | last post by:
Is there a way to make Postgresql case-INSENSITIVE? Thanks
1
by: Robert Sander | last post by:
Hi, I have to do some case-insensitive queries on a XML document using XPath. Because XML 1.0 and XPath 1.0 are case-sensitive this is a little bit tricky. Sample document: <books>...
3
by: Michael C | last post by:
Hi all, I'm using a SortedList to store data, and want the keys to be compared in case insensitive order, so that mySList is the same as mySList
2
by: Cesar Ronchese | last post by:
Hi all. I have some codes using the System.XML objects to find my configurations (object.SelectNode -or- object.SelectNodes). The problem is I need suply the XPath string with case sensitive....
2
by: John | last post by:
Does anyone know how to how to performance case-insensitive search on XML data type in SQLServer 2005? Or I have to convert all the xml data to lower case before I store it? Thanks in advance....
6
by: Randeh | last post by:
Here's my working code for simple a 2-D alphabetical bubble sort. All I need now is to just make it case insensitive (ignores capitalization) and I've been trying to throw toupper or tolower in...
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:
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.