当前位置:网站首页>【C#】判断字符串中是否包含指定字符或字符串(Contains/IndexOf)
【C#】判断字符串中是否包含指定字符或字符串(Contains/IndexOf)
2022-07-31 07:25:00 【厦门德仔】
判断字符串中是否包含指定字符或字符串(Contains/IndexOf)
一:使用string.Contains(str)方法
String.Contains对大小写敏感,适用于区分大小写的判断。返回值为bool型
二:使用sring.IndexOf(str)方法
IndexOf 函数对大小写不敏感,适用于不区分大小写的判断。返回值为int型,str 在sring中的索引值
var str = "abcdefg";
str.Contains("Bcd");//返回false
str.Contains("bcd");//返回true
str.IndexOf("bc");//返回1
str.IndexOf("BC");//返回1
注意:对中文进行判断时,没有大小写之分string.Contains的效率更高些
边栏推荐
猜你喜欢

Linked list implementation and task scheduling

Leetcode952. 按公因数计算最大组件大小

Environment_Variable_and_SetUID
![[Interview: Concurrency 38: Multithreading: Thread Pool] Basic concepts of the ThreadPoolExecutor class](/img/b2/c53b72a151b1277aee5aeb65c61cf7.png)
[Interview: Concurrency 38: Multithreading: Thread Pool] Basic concepts of the ThreadPoolExecutor class

完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?

Locust 1.0版本引入的变化

Visual Studio新功能出炉:低优先级构建

安装部署KubeSphere管理kubernetes

2022.07.13_每日一题

2022.07.14_Daily Question
随机推荐
MySQL table creation statement_Three commonly used MySQL table creation statements
Shell编程之条件语句
Yu Mr Series 】 【 2022 July 022 - Go Go teaching course of container in the dictionary
linux redis6.2.6配置文件
一文搞定代码中的命名
2704:寻找平面上的极大点
波士顿房价数据集 Boston house prices dataset
Spark 在 Yarn 上运行 Spark 应用程序
'vite' is not an internal or external command, nor is it a runnable program or batch file.
使用PageHelper实现分页查询(详细)
CY7C68013A之LED闪烁
2022.07.15_每日一题
Leetcode952. 按公因数计算最大组件大小
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
2022.07.18 _ a day
2022.07.20_每日一题
The Spark run on Yarn Spark application
Practical Bioinformatics 2: Multi-omics data integration and mining
2022.07.13_Daily Question
Calculation example of matlab program iEEE9 node system for power flow calculation of AC-DC hybrid system based on alternate iteration method