Skip to content

System.String should be consistent with taking StringComparison arguments #14504

Closed

Description

@terrajobst

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.

Activity

  1. ellismg commented on Apr 28, 2015

    @ellismg
    Contributor

    We should also ensure that the CompareInfo class exposes relevant methods, for folks that want to use a non-invariant, linguistic comparison.

  2. terrajobst commented on Feb 23, 2016

    @terrajobst
    ContributorAuthor

    Moving to future as it doesn't make the RTM bar.

  3. karelz commented on Nov 18, 2016

    @karelz
    Member

    We need formal API proposal

  4. gsfreema commented on Feb 6, 2018

    @gsfreema
    Contributor

    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?"

  5. gsfreema commented on Feb 6, 2018

    @gsfreema
    Contributor

    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.

  6. karelz commented on Feb 6, 2018

    @karelz
    Member

    See formal API review - we need someone to do a sweep and find out what else is missing, then propose API.

  7. danmoseley commented on Jan 3, 2019

    @danmoseley
    Contributor

    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.

  8. danmoseley commented on Jan 8, 2019

    @danmoseley
    Contributor

    @terrajobst do you want to create the proposal since this is something you'd like to get into NS21?

  9. terrajobst commented on Jan 25, 2019

    @terrajobst
    ContributorAuthor

    Looks like we're now consistent:

    Contains(Char);
    Contains(Char, StringComparison);
    Contains(String);
    Contains(String, 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.

  10. transferred this issue fromdotnet/corefxon Jan 31, 2020
  11. added this to the 3.0 milestone on Jan 31, 2020
  12. ghost locked as resolved and limited conversation to collaborators on Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionarea-System.Runtimehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions