【问题标题】:find variable on an other one with powershell using substring使用子字符串使用powershell在另一个变量上查找变量
【发布时间】:2019-01-07 18:16:58
【问题描述】:

我想用powershell检查变量A的内容是否存在于内容变量B中:

variable A = PROD 
variable B = xxxxxPRODxxxx

【问题讨论】:

    标签: powershell powercli


    【解决方案1】:

    你可以使用 -match 来比较使用正则表达式

    $keyword = 'PROD'
    $string = 'xxxxxPRODxxxxx'
    if($string -match $keyword){write-host 'matched'}
    

    【讨论】:

      【解决方案2】:

      要么使用String.Contains() 方法:

      $A = 'PROD'
      $B = 'xxxxPRODxxxx'
      $B.Contains($A)
      

      或使用-like 运算符:

      $B -like "*$A*"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-11
        • 1970-01-01
        • 2022-11-24
        • 2014-03-10
        • 2015-06-21
        • 2018-08-27
        • 2014-03-13
        • 1970-01-01
        相关资源
        最近更新 更多