当前位置:网站首页>【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的效率更高些
边栏推荐
猜你喜欢

CNN--Introduction to each layer

NK - RTU980 burning bare-metal program
![Embedded system driver primary [2] - _ parameters and dependencies under the kernel module](/img/c2/22c1e087b92ed2c898f97bcf0e818b.png)
Embedded system driver primary [2] - _ parameters and dependencies under the kernel module

Financial leasing business

【愚公系列】2022年07月 Go教学课程 022-Go容器之字典

Locust 1.0版本引入的变化

2022.07.12 _ a day

使用PageHelper实现分页查询(详细)
![[Interview: Concurrency 37: Multithreading: Thread Pool] Custom Thread Pool](/img/61/71131414c48bb77aa9160b61a68811.png)
[Interview: Concurrency 37: Multithreading: Thread Pool] Custom Thread Pool

电脑开机密码怎么设置?如何给你的电脑加上“安全锁”
随机推荐
金融租赁业务
R语言 第一部分
2022.07.24_每日一题
Ceph single node deployment
【面试题】从输入URL到游览器渲染完成,经历了什么
[PSQL] 复杂查询
Failure scenarios of @Transactional annotations
MySQL 8.0.29 解压版安装教程(亲测有效)
任务及任务切换
2022.07.12_每日一题
7/28-7/29 Expectation + thinking + suffix array + ST table
Calculation example of matlab program iEEE9 node system for power flow calculation of AC-DC hybrid system based on alternate iteration method
CNN--各层的介绍
第9章 异常try...except...else...finally
mysql的建表语句_三种常用的MySQL建表语句
链表实现及任务调度
The Ballad of Lushan Sends Lu's Servant to the Void Boat
【Objective-C语言中的@property】
Jetpack Compose学习(8)——State及remeber
关于yum源的配置及更新