c# - 以不区分大小写的方式查找子字符串 - C#

标签 c# .net

<分区>

Possible Duplicate:
Case insensitive contains(string)

使用 String 类的 Contains() 方法可以找到一个子字符串。 如何以不区分大小写的方式在字符串中查找子串?

最佳答案

您可以使用 IndexOf() 方法,它接收一个 StringComparison 类型:

string s = "foobarbaz";
int index = s.IndexOf("BAR", StringComparison.CurrentCultureIgnoreCase); // index = 3

如果未找到字符串,IndexOf() 返回 -1。

关于c# - 以不区分大小写的方式查找子字符串 - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8494703/

相关文章:

c# - .NET 计时器异步运行吗?

c# - 访问修饰符会影响扩展方法吗?

c# - ViewModel 替换复杂的匿名对象

c# - 如何在 .Net Core 中要求非匿名用户?

.net - 如果我在 GAC 中有两个同名的程序集,我如何告诉 .Net 使用哪个程序集?

Android Activity 和服务关系

.net - 打开位于 addin 文件夹中的 XML 文件

.net - Azure.Identity 库(例如 DefaultAzureCredential)是否支持 token 缓存?

c# - 在 .NET Compact Framework 的托管代码 (C#) 中使用非托管 (C) 缓冲区

c# - 并行线程中的多个 dbcontext,EntityException "Rerun your statement when there are fewer active users"