手机
当前位置:查字典教程网 >脚本专栏 >PowerShell >PowerShell Contains函数查找字符串实例
PowerShell Contains函数查找字符串实例
摘要:本文介绍在PowerShell中使用字符串的Contains函数,来查询一个字符串中是否存在另一个字符串。Contains()函数是从Str...

本文介绍在PowerShell中使用字符串的Contains函数,来查询一个字符串中是否存在另一个字符串。

Contains()函数是从String对象中继承过来的,可以直接用于字符串的查找判断。Contains()函数的返回值是一个布尔值,即True或False,它表示的含义是存在或不存在。

举例如下:

“123“中存在1

复制代码 代码如下:PS C:Usersspaybow> "123".contains("1")

True

”123“中存在”12“

复制代码 代码如下:PS C:Usersspaybow> "123".contains("12")

True

”123“中存在123

复制代码 代码如下:PS C:Usersspaybow> "123".contains("123")

True

”123“中不存在”13“

复制代码 代码如下:PS C:Usersspaybow> "123".contains("13")

False

因为只是存在是否存在,所以Contains函数无法定位查询字符串在被查询字符串中的位置。如果需要定位它的位置,则需要使用到IndexOf函数,这个函数我们即将介绍。

关于PowerShell使用Contains函数查找字符串,本文就介绍这么多,希望对您有所帮助,谢谢!

【PowerShell Contains函数查找字符串实例】相关文章:

PowerShell定义函数参数的2种方法和传参方法实例

PowerShell函数参数使用智能提示功能例子

PowerShell多线程执行前后台作业的例子

PowerShell中使用GetType获取变量数据类型

PowerShell中的$Input变量使用实例

PowerShell函数参数用星号隐藏的方法

PowerShell函数中接收管道参数实例

PowerShell中查找字符串位置的IndexOf函数使用实例

PowerShell函数实现类似重载功能实例

PowerShell函数参数指定数据类型实例

精品推荐
分类导航