Powershell,删除特定字符(空格和连字符)

Powershell, remove specific characters (spaces and hyphens)

我有这个字符串:' - app-name'。所以这是双 spaces,连字符,space,应用程序名称。

我想去掉这些双 space、连字符、space。所以结果将是 app-name

我尝试了 ' - app-name'.Trim(" - ", " ") 但那不起作用。

我该怎么做?

谢谢

对字符串使用 Replace() 方法:

$test = "  - app-name"
$test.replace(" - ", "")

输出:appname

Trim 只接受一个参数。

' - app-name'.Trim(" - ") 有效。