In Powershell how can I convert a string with a trailing 'sign' to a number? In Powershell how can I convert a string with a trailing 'sign' to a number? powershell powershell

In Powershell how can I convert a string with a trailing 'sign' to a number?


EDIT: as per Halr9000's suggestion

$foo = "300-";$bar = 0;$numberStyles = [System.Globalization.NumberStyles];$cultureInfo = [System.Globalization.CultureInfo];[int]::TryParse($foo, $numberStyles::AllowTrailingSign, $cultureInfo::CurrentCulture, [ref]$bar);


[System.Globalization.NumberStyles]::AllowTrailingSign

I should also point out, that when I'm dealing with enums in general, sometimes I can get by typing a string. E.g. in this case, just put

"AllowTrailingSign"

Final note, when quizzing an Enum for all possible values, use the line:

[System.Globalization.NumberStyles] | gm -static


Here's a better way to get the enum values:

$type = [System.Globalization.NumberStyles][enum]::GetValues($type)