views:

106

answers:

3

Hi all,

How can I make the line below case insensitive?

drUser["Enrolled"] = (enrolledUsers.FindIndex(x => x.Username == (string)drUser["Username"]) != -1);

I was given some advice earlier today that suggested I use:

x.Username.Equals((string)drUser["Username"], StringComparison.OrdinalIgnoreCase)));

the trouble is I can't get this to work, I've tried the line below, this compiles but returns the wrong results, it returns enrolled users as unenrolled and unrolled users as enrolled.

drUser["Enrolled"] = (enrolledUsers.FindIndex(x => x.Username.Equals((string)drUser["Username"], StringComparison.OrdinalIgnoreCase)));

Can anyone point out the problem?

Thanks Jamie

A: 

How about using StringComparison.CurrentCultureIgnoreCase instead?

decyclone
A: 

I'm not sure about the problem you're having with user enrollments, but for a case-insensitive string comparison, try this:

String.Compare(x.Username, (string)drUser["Username"], true) == 0
BoltClock
+2  A: 

You should use static String.Compare function like following

x => String.Compare (x.Username, (string)drUser["Username"],
                     StringComparison.OrdinalIgnoreCase) == 0
Oleg