You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.String should be consistent with taking StringComparison arguments #14504
Every method on System.String that compares strings should take a StringComparison argument. An example where that's not the case is, String.Contains. We should to a holistic pass to make sure we don't miss others.
Reacted by Jon Hanna, GSPP, Joseph Musser and Daniel Schroeder
Is it possible to start small with a task such as this? I was doing a code review at work and saw someone calling s1.ToLower().Contains(s2) and was surprised that there wasn't a version that takes the StringComparison enum.
The implementation for such a function could be as simple as return s1.IndexOf(s2, StringComparison.OrdinalIgnoreCase) != -1;.
Would this form of String.Contains be something worthy of going into the framework, or would it be expected that people write their own extension methods for these specific cases? If you need an API proposal, would you need it for something as broad as "all string comparison functions need to accept StringComparison" or could it be something like "String.Contains needs to an overload accepting StringComparison?"
I looked at the other methods and with respect to StringComparison nothing sticks out. And with respect to .NET Standard, the overloads taking StringComparison got added in dotnet/standard#823.
Activity
ellismg commentedon Apr 28, 2015
We should also ensure that the
CompareInfoclass exposes relevant methods, for folks that want to use a non-invariant, linguistic comparison.terrajobst commentedon Feb 23, 2016
Moving to future as it doesn't make the RTM bar.
karelz commentedon Nov 18, 2016
We need formal API proposal
gsfreema commentedon Feb 6, 2018
Is it possible to start small with a task such as this? I was doing a code review at work and saw someone calling
s1.ToLower().Contains(s2)and was surprised that there wasn't a version that takes theStringComparisonenum.The implementation for such a function could be as simple as
return s1.IndexOf(s2, StringComparison.OrdinalIgnoreCase) != -1;.Would this form of String.Contains be something worthy of going into the framework, or would it be expected that people write their own extension methods for these specific cases? If you need an API proposal, would you need it for something as broad as "all string comparison functions need to accept StringComparison" or could it be something like "String.Contains needs to an overload accepting StringComparison?"
gsfreema commentedon Feb 6, 2018
Actually, I just saw that this was added to
String.Searching.cs. Perhaps that work needs to be linked to this issue so it can eventually be closed.karelz commentedon Feb 6, 2018
See formal API review - we need someone to do a sweep and find out what else is missing, then propose API.
danmoseley commentedon Jan 3, 2019
As noted above, the work here is to create an API proposal. We could get the new API into .NET Standard 2.1 if it is defined and approved.
danmoseley commentedon Jan 8, 2019
@terrajobst do you want to create the proposal since this is something you'd like to get into NS21?
terrajobst commentedon Jan 25, 2019
Looks like we're now consistent:
I looked at the other methods and with respect to
StringComparisonnothing sticks out. And with respect to .NET Standard, the overloads takingStringComparisongot added in dotnet/standard#823.