![](/img/trans.png)
[英]String.IndexOf(Char) vs String.IndexOf(Char, StringComparison)
[英]What is the StringComparison method of string.IndexOf(string)?
我知道string.IndexOf("some string")
正在執行區分大小寫和區分文化的比較。
[...] 此方法使用當前區域性執行單詞(區分大小寫和區域性)搜索。 搜索從該實例的第一個字符 position 開始,一直持續到最后一個字符 position。 [...]
但是,這是否意味着它等同於使用string.IndexOf("some string", StringComparison.CurrentCulture)
?
我想知道StringComparison
的哪個精確成員正在使用或等效使用。
是的。
這是源代碼: https://source.dot.net/#System.Private.CoreLib/String.Searching.cs,cf9e6bfe83442551,references
public int IndexOf(string value)
{
return IndexOf(value, StringComparison.CurrentCulture);
}
是的,.NET 框架(和核心)源可用,所以這里是相關代碼: https://referencesource.microsoft.com/#mscorlib/system/string.cs,2307
public int IndexOf(String value) { return IndexOf(value, StringComparison.CurrentCulture); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.