在Powershell中,如何将带有尾随"符号"的字符串转换为数字?

Rob*_*son 6 globalization powershell type-conversion

我需要使用Powershell将带有可选尾部符号的字符串转换为实际数字.

可能的字符串是:

  • 1000-
  • 323+
  • 456

我正在尝试使用带有NumberStyles的AllowTrailingSign的System.Int.TryParse,但我无法弄清楚如何使Powershell可以使用System.Globalization.NumberStyles.

Jim*_*ger 5

编辑:根据Halr9000的建议

$foo = "300-";
$bar = 0;
$numberStyles = [System.Globalization.NumberStyles];
$cultureInfo = [System.Globalization.CultureInfo];

[int]::TryParse($foo, $numberStyles::AllowTrailingSign, $cultureInfo::CurrentCulture, [ref]$bar);
Run Code Online (Sandbox Code Playgroud)