Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where has StringComparison.InvariantCultureIgnoreCase gone?

I'm porting C# code to a Windows Store App. To my surprise the following code does not work anymore:

someString.Equals("someOtherString", StringComparison.InvariantCultureIgnoreCase)

InvariantCulture and InvariantCultureIgnoreCase have been removed(*) from StringComparison.

Why?

And how do I replace it?

Edit: (*) Strictly speaking, it has not been removed, it is merely not available for Windows Store Apps. The result is the same: You cannot use it.

like image 779
Sebastian Negraszus Avatar asked Jan 30 '13 09:01

Sebastian Negraszus


People also ask

What is StringComparison InvariantCultureIgnoreCase?

InvariantCultureIgnoreCase. The StringComparer returned by the InvariantCultureIgnoreCase property compares strings in a linguistically relevant manner that ignores case, but it is not suitable for display in any particular culture.

What does StringComparison OrdinalIgnoreCase do?

OrdinalIgnoreCase members of the new StringComparison enumeration. These enforce a byte-by-byte comparison similar to strcmp that not only avoids bugs from linguistic interpretation of essentially symbolic strings, but provides better performance.


2 Answers

Those specific options have not gone anywhere, but they are just not supported by Windows Store Apps.

If you look at MSDN for StringComparison Enumeration you'll see those specific options are not supported by the Portable library or .NET for Windows Store.

The only options that are supported for the Portable Library or Windows Store Apps are:

  • CurrentCulture
  • CurrentCultureIgnoreCase
  • Ordinal
  • OrdinalIgnoreCase

I can't speak for why, but there is not an option to "replace" as those values do not exist within the framework. You'll have to work with one of the other options that do exist, StringComparison.OrdinalIgnoreCase is probably going to be the easiest to work with.

like image 99
psubsee2003 Avatar answered Oct 21 '22 10:10

psubsee2003


It looks like it doesn't support Windows Store App.

For Windows Store App, only avaiable you can use with green bag enumerations;

enter image description here

For general idea, people used OrdinalIgnoreCase in this case.

https://github.com/loqu8/sqlite-net/commit/bfa04a6a40b4f62000bb9c57d5517643404c9109

like image 29
Soner Gönül Avatar answered Oct 21 '22 09:10

Soner Gönül