pwershell switch 语句

原文这里

  和其他语言的用法大体一致,一般用在多个条件下一个值得判定。

  需要注意的是powershell里使用注意:

  1. 可以通过 -wildcard -regex 来对要判断的值使用通配符或是正则表达式
  2. 可以对数组进行判定,遍历数组每一个值
  3. 跳出要使用break,否则会全部进行一次条件测试
switch -wildcard ($a) 
    { 
        "?14150" {"The color is red."; break} 
        "?14151" {"The color is blue."; break} 
        "?14152" {"The color is green."; break} 
        "?14153" {"The color is yellow."; break} 
        "?14154" {"The color is orange."; break} 
        "?14155" {"The color is purple."; break} 
        "?14156" {"The color is pink."; break}
        "?14157" {"The color is brown."; break} 
        default {"The color could not be determined."}

 

posted @ 2017-12-01 17:41  newone  阅读(160)  评论(0编辑  收藏  举报