【问题标题】:What is the StringComparison method of string.IndexOf(string)?string.IndexOf(string) 的 StringComparison 方法是什么?
【发布时间】:2020-04-25 19:08:03
【问题描述】:

我知道string.IndexOf("some string") 正在执行区分大小写和区分文化的比较。

MSDN page.

[...] 此方法使用当前区域性执行单词(区分大小写和区域性)搜索。搜索从该实例的第一个字符位置开始,一直持续到最后一个字符位置。 [...]

但是,这是否意味着它等同于使用string.IndexOf("some string", StringComparison.CurrentCulture)
我想知道StringComparison 的哪个精确成员正在被使用或等价于被使用。

【问题讨论】:

    标签: c# string string-comparison


    【解决方案1】:

    是的,.NET Framework(和核心)源是可用的,所以这里是相关代码:https://referencesource.microsoft.com/#mscorlib/system/string.cs,2307

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

    【讨论】:

    • 谢谢你们! :)
    【解决方案2】:

    是的。

    这里是源代码:https://source.dot.net/#System.Private.CoreLib/String.Searching.cs,cf9e6bfe83442551,references

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

    【讨论】:

    • 谢谢你们! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 2013-12-29
    • 2012-01-25
    • 2018-10-15
    • 2013-08-11
    • 2015-02-23
    相关资源
    最近更新 更多