== Why is this an issue?

``++string.ToLower()++``, ``++ToUpper++``, ``++IndexOf++``, ``++LastIndexOf++``, and ``++Compare++`` are all culture-dependent, as are some (floating point number and ``++DateTime++``-related) calls to ``++ToString++``. Fortunately, all have variants which accept an argument specifying the culture or formatter to use. Leave that argument off and the call will use the system default culture, possibly creating problems with international characters.


``++string.CompareTo()++`` is also culture specific, but has no overload that takes a culture information, so instead it's better to use ``++CompareOrdinal++``, or ``++Compare++`` with culture.


Calls without a culture may work fine in the system's "home" environment, but break in ways that are extremely difficult to diagnose for customers who use different encodings. Such bugs can be nearly, if not completely, impossible to reproduce when it's time to fix them.

=== Noncompliant code example

[source,csharp]
----
var lowered = someString.ToLower(); //Noncompliant
----

=== Compliant solution

[source,csharp]
----
var lowered = someString.ToLower(CultureInfo.InvariantCulture);
----

or


[source,csharp]
----
var lowered = someString.ToLowerInvariant();
----


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

* Define the locale to be used in this string operation.
* Use "CompareOrdinal" or "Compare" with the locale specified instead of "CompareTo".


'''
== Comments And Links
(visible only on this page)

=== on 2 Jul 2015, 07:16:27 Tamas Vajk wrote:
\[~ann.campbell.2] LGTM

=== on 6 Jul 2015, 14:47:32 Ann Campbell wrote:
\[~tamas.vajk] I've just mapped this parent task to SpecifyACultureInStringConversionExplicitly for SONARCSANA-178. I'm wondering if this rule's other cases cover any other R# rules.

=== on 8 Jul 2015, 09:23:00 Tamas Vajk wrote:
\[~ann.campbell.2] Looks good. I added a few more R# IDs to the parent RSPEC.

=== on 9 Jul 2015, 13:40:14 Ann Campbell wrote:
Updated to include SONARCSANA-221

=== on 26 Nov 2015, 15:38:15 Tamas Vajk wrote:
\[~ann.campbell.2] I modified the scope of this rule. Only operations specified on ``++String++`` are left here, ``++IEnumerable<String>++`` operations have been removed. The main reason is that we we can't force users to define an ``++IComparer++`` for these operations, as it's unreasonably long (in contrary to the ``++IFormatProvider++``, which can be added as a ``++CultureInfo++``). Here is how it's done in .NET4.5: ``++new string[] { }.OrderBy(s => s, Comparer<string>.Create((x, y) => x.CompareTo(y)))++``, but for prior versions you would need to declare a new class and instantiate that.


Another thing that has been removed is the ``++==++``, which is culture specific, but I don't think that we want to force .NET devs to use ``++Equals++`` instead.


cc [~dinesh.bolkensteyn] (you were assigned to this ticket for reviewing)

=== on 2 Dec 2015, 16:35:42 Ann Campbell wrote:
Okay. Thanks [~tamas.vajk]

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
