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

前端 未结 7 620
栀梦
栀梦 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条回答
  • 2020-12-05 13:27

    You can use the -as operator. If casting succeed you get back a number:

    $numberAsString -as [int]
    
    0 讨论(0)
提交回复
热议问题