Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed usage of Contains, IndexOf, and LastIndexOf that didn't use Str…
…ingComparison.Ordinal, to combat a possible breaking change in .NET 5.0. See: dotnet/runtime#43736
- Loading branch information
15bd6d8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also do
IndexOf('`')
The char overload is always ordinal.
15bd6d8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment. How are you so sure?
15bd6d8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ordinal / culture-insensitive behavior is documented for the IndexOf(char) method under remarks. This is true for both .NET framework and .NET core. Only the IndexOf(string... ) methods are culture sensitive.
SEE --
https://docs.microsoft.com/en-us/dotnet/api/system.string.indexof?view=netcore-3.1#System_String_IndexOf_System_Char_
This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if their Unicode scalar values are the same.
15bd6d8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this seems to be changing in .NET Core 5.0, as this issue reports. That said, the "`" character might be unaffected, but better safe than sorry :-)