• 在 PowerShell 中,–Match、Like 和 –Contains 有什么区别?


    转自:https://www.nhooo.com/note/qa0gd1.html

    首先使用三种用法进行示例:

    PS C:\WINDOWS\system32> "This is a PowerShell String" -Match "PowerShell"
    True
    PS C:\WINDOWS\system32> "This is a PowerShell String" -Like "PowerShell"
    False
    PS C:\WINDOWS\system32> "This is a PowerShell String" -Contains "PowerShell"
    False

    1、Match 表示判断右侧字符串是否在左侧字符串中,其实是在匹配正则表达式;

    2、Like 的用法与 SQL 中类似,在需要匹配的字符串左右需要增加 * 来代表通配符,用法示例:

    PS C:\WINDOWS\system32> "This is a PowerShell String" -like "*PowerShell*"
    True

    3、Contains 是用来判断数组中是否包含元素,在对字符串使用时,则将字符串拆分为字符数组进行判断

    用法示例:

    PS C:\WINDOWS\system32> "Apple","Dog","Carrot","Cat" -contains "dog"
    True

    唔,所以不要用错哦~

    更多比较运算符参考:https://docs.microsoft.com/zh-cn/powershell/scripting/learn/deep-dives/everything-about-if

    Where-Object 参考:https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/where-object

    Select-Object 参考:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object

  • 相关阅读:
    IO流
    myEclipse的使用
    单例模式
    日期的使用
    String类的常用方法
    break、continue和return的区别
    包装类和随机数
    enum类的使用
    Java基础概念性的知识总结
    汇编中的函数调用与递归
  • 原文地址:https://www.cnblogs.com/xwgli/p/16164763.html
Copyright © 2020-2023  润新知