Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net core / standard string.ToLower() has no culture parameter

In .net fx i can do

myString.ToLower(frenchCulture);

But when looking at .net core or .net standard there is no more a culture parameter that can be passed. There is only string.ToLower() and string.ToLowerInvariant()

Should the culture just be ommitted ? But shouldn't then there be issues when the culture of the string is not the current culture?

Any hints what the reason behind this is?

When I have the idea of a invariant culture I can use ToLowerInvariant().

But what about use cases where i have to use string.ToLower() in a culture that is not the current culture?

like image 296
Boas Enkler Avatar asked May 24 '17 10:05

Boas Enkler


People also ask

How to use ToLower Method in c#?

This method is used to return a copy of the current string converted to lowercase. Syntax: public string ToLower (); Return Type: It return the string value, which is the lowercase equivalent of the string of type System.

What does ToLower return in C#?

ToLower() Returns a copy of this string converted to lowercase.

Is ToUpper faster than ToLower?

The other three are mostly the same. But in general, ToLowerInvariant is fastest, then ToUpper and then ToUpperInvariant .


1 Answers

It looks like the capability is there, just in a more roundabout way. Instead of:

string output = input.ToLower(culture);

use

string output = culture.TextInfo.ToLower(input);

Also note that the overload has been added in netstandard2.0. The implementation is basically the code above.

like image 154
Jon Skeet Avatar answered Sep 25 '22 17:09

Jon Skeet