Search code examples
c#stringstring-comparison

What is the StringComparison method of string.IndexOf(string)?


I know string.IndexOf("some string") is performing a case-sensitive and culture-sensitive comparison.

MSDN page.

[...] This method performs a word (case-sensitive and culture-sensitive) search using the current culture. The search begins at the first character position of this instance and continues until the last character position. [...]

However, does that mean it is equivalent to using string.IndexOf("some string", StringComparison.CurrentCulture)?
I'd like to know which precise member of StringComparison is being used or is equivalent to be used.


Solution

  • Yes, the .NET Framework (and core) source is available, so here is the relevant code : https://referencesource.microsoft.com/#mscorlib/system/string.cs,2307

    public int IndexOf(String value) {
                return IndexOf(value, StringComparison.CurrentCulture);
            }