dotnet / dotnet/docs

Additional clarity around ordinal vs culture-sensitive comparisons

Open
#27,011 0 comments 0 reactions 0 assignees View on GitHub
dotnet-fundamentals/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

The section "Ordinal vs. linguistic search and comparison" should be updated to explain why the example given in the "Behavioral differences" section (searching for newline) is a culture-sensitive operation. "Behavioral differences" can then suggest that people read "Ordinal vs. linguistic search and comparison" for that explanation.

It would also be helpful to show the correct behaviour in "Behavioral differences", i.e.:

```csharp
string s = "Hello\r\nworld!";
int idxCultureSensitive = s.IndexOf("\n");
Console.WriteLine(idxCultureSensitive );

// The above snippet prints:
//
// '6' when running on .NET Framework (Windows)
// '6' when running on .NET Core 2.x - 3.x (Windows)
// '-1' when running on .NET 5 (Windows)
// '-1' when running on .NET Core 2.x - 3.x or .NET 5 (non-Windows)
// '6' when running on .NET Core 2.x or .NET 5 (in invariant mode)

int idxCultureInsensitive = s.IndexOf("\n", StringComparison.Ordinal);
Console.WriteLine(idxCultureInsensitive);

// The above snippet prints 6 on all platforms.
```

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: ff20a875-d296-266f-8e5b-a3ab32db2491
* Version Independent ID: 1788f46c-cdad-9ea5-7bd7-62c959255fd5
* Content: [Behavior changes when comparing strings on .NET 5+](https://docs.microsoft.com/en-us/dotnet/standard/base-types/string-comparison-net-5-plus#feedback)
* Content Source: [docs/standard/base-types/string-comparison-net-5-plus.md](https://github.com/dotnet/docs/blob/main/docs/standard/base-types/string-comparison-net-5-plus.md)
* Product: **dotnet-fundamentals**
* GitHub Login: @adegeo
* Microsoft Alias: **adegeo**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.