Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a string to ordinal upper or lower case

Is it possible to convert a string to ordinal upper or lower case. Similar like invariant.

string upperInvariant = "ß".ToUpperInvariant();
string lowerInvariant = "ß".ToLowerInvariant();
bool invariant = upperInvariant == lowerInvariant; // true

string upperOrdinal = "ß".ToUpperOrdinal(); // SS
string lowerOrdinal = "ß".ToLowerOrdinal(); // ss
bool ordinal = upperOrdinal == lowerOrdinal; // false

How to implement ToUpperOrdinal and ToLowerOrdinal?

Edit: How to to get the ordinal string representation? Likewise, how to get the invariant string representation? Maybe that's not possible as in the above case it might be ambiguous, at least for the ordinal representation.

Edit2:

string.Equals("ß", "ss", StringComparison.InvariantCultureIgnoreCase); // true

but

"ß".ToLowerInvariant() == "ss"; // false
like image 360
Wouter Avatar asked Jan 04 '17 14:01

Wouter


People also ask

How can we convert a string to uppercase and lowercase?

The toUpperCase() method converts a string to upper case letters. Note: The toLowerCase() method converts a string to lower case letters.

Which string method converts a string of characters to upper case?

upper() method on a string converts all of the characters to uppercase, whereas the lower() method converts all of the characters to lowercase.

Is ToUpper better than Tolower?

ToUpper depends on what your strings contain more of, and that typically strings contain more lower case characters which makes ToLower more efficient.

How do you convert a set of string variable to lowercase?

The toLowerCase method converts a string to lowercase letters. The toLowerCase() method doesn't take in any parameters. Strings in JavaScript are immutable. The toLowerCase() method converts the string specified into a new one that consists of only lowercase letters and returns that value.


1 Answers

From msdn:

TheStringComparer returned by the OrdinalIgnoreCase property treats the characters in the strings to compare as if they were converted to uppercase using the conventions of the invariant culture, and then performs a simple byte comparison that is independent of language.

But I'm guessing doing that won't achieve what you want, since simply doing "ß".ToUpperInvariant() won't give you a string that is ordinally equivallent to "ss". There must be some magic in the String.Equals method that handles the speciall case of Why “ss” equals 'ß'.

If you're only worried about German text then this answer might help.

like image 174
James Crosswell Avatar answered Oct 02 '22 19:10

James Crosswell