pwershell switch 语句
和其他语言的用法大体一致,一般用在多个条件下一个值得判定。
需要注意的是powershell里使用注意:
- 可以通过 -wildcard -regex 来对要判断的值使用通配符或是正则表达式
- 可以对数组进行判定,遍历数组每一个值
- 跳出要使用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."}