In Powershell what is the idiomatic way of converting a string to an int?

前端 未结 7 657
栀梦
栀梦 2020-12-05 12:32

The only method I have found is a direct cast:

> $numberAsString = \"10\"
> [int]$numberAsString
10

Is this the standard approach in

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 13:19

    A quick true/false test of whether it will cast to [int]

    [bool]($var -as [int] -is [int])
    

提交回复
热议问题