PowerShell:从键盘输入一个字符串,统计字符串中几个大写字母,几个小写字母,几个数字,几个特殊符号?

从键盘输入一个字符串,统计字符串中几个大写字母,几个小写字母,几个数字,几个特殊符号?

[string]$a = Read-Host "请输入一个字符串"

[int]$num = 0

[int]$big = 0

[int]$smo = 0

[int]$others = 0

[char[]]$c = $a.tochararray()

foreach($d in $c){

    [int]$d = $d

    if($d -ge 48 -and $d -le 57){

    $num++

}elseif($d -ge 65 -and $d -le 90){

   $big++

}elseif($d -ge 97 -and $d -le 122){

   $smo++

}else{

   $others++

}

}write-output($num++,$big++,$smo++,$others++)

主要语法:if  foreach

猜你喜欢

转载自blog.csdn.net/Littleliuing/article/details/106911004