Are .NET string operations case sensitive?

前端 未结 4 2389
时光说笑
时光说笑 2021-02-20 09:33

Are .NET string functions like IndexOf(\"blah\") case sensitive?

From what I remember they aren\'t, but for some reason I am seeing bugs in my app where the

4条回答
  •  面向向阳花
    2021-02-20 10:13

    Yes, string functions are case sensitive by default. They typically have an overload that lets you indicate the kind of string comparison you want. This is also true for IndexOf. To get the index of your string, in a case-insensitive way, you can do:

    string blaBlah = "blaBlah";
    int idx = blaBlah.IndexOf("blah", StringComparison.OrdinalIgnoreCase);
    

提交回复
热议问题