相关疑难解决方法(0)

String.Contains()比String.IndexOf()更快吗?

我有一个大约2000个字符的字符串缓冲区,如果它包含一个特定的字符串,需要检查缓冲区.
将针对每个webrequest在ASP.NET 2.0 webapp中进行检查.

有谁知道String.Contains方法是否比String.IndexOf方法表现更好?

    // 2000 characters in s1, search token in s2
    string s1 = "Many characters. The quick brown fox jumps over the lazy dog"; 
    string s2 = "fox";
    bool b;
    b = s1.Contains(s2);
    int i;
    i = s1.IndexOf(s2);
Run Code Online (Sandbox Code Playgroud)

有趣的事实

.net c# asp.net string performance

110
推荐指数
6
解决办法
10万
查看次数

标签 统计

.net ×1

asp.net ×1

c# ×1

performance ×1

string ×1