查找不区分大小写的方式子 - C# [英] Find a substring in a case-insensitive way - C#

查看:342
本文介绍了查找不区分大小写的方式子 - C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
不区分大小写包含(字符串)

通过包含String类的()办法一个子都可以找到。
如何找到在不区分大小写的方式串子?

With Contains() method of String class a substring can be found. How to find a substring in a string in a case-insensitive manner?

推荐答案

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

You can use the IndexOf() method, which takes in a StringComparison type:

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

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

If the string was not found, IndexOf() returns -1.

这篇关于查找不区分大小写的方式子 - C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆