当前位置:网站首页>【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的效率更高些
边栏推荐
- sort函数(快速排列)的使用方法
- Regarding "computing power", this article is worth reading
- 初识NK-RTU980开发板
- MySql database optimization query tool
- Open Source | Commodity Recognition Recommender System
- ZCMU--1862: zbj的狼人杀
- ros小乌龟画图
- Navicat new database
- Leetcode952. Calculate maximum component size by common factor
- mysql插入新字段方法
猜你喜欢
随机推荐
Unreal基础概念
Vscode: Project-tree plugin
2022.07.12_每日一题
MySQL 5.7 安装教程(全步骤、保姆级教程)
MySQL 5.7升级到8.0详细过程
Failure scenarios of @Transactional annotations
2022.07.15_Daily Question
MySQL安装到最后一步 write configuration file 失败 怎么办?及后安装步骤
uniapp 高度不自适应
2022.07.26_Daily Question
[Interview: Concurrency 37: Multithreading: Thread Pool] Custom Thread Pool
Visual Studio新功能出炉:低优先级构建
MySql数据库优化查询工具
Financial leasing business
MySQL table creation statement_Three commonly used MySQL table creation statements
2022.07.13_Daily Question
Open Source | Commodity Recognition Recommender System
波士顿房价数据集 Boston house prices dataset
【面试题】从输入URL到游览器渲染完成,经历了什么
2022.07.18_每日一题