Removing spaces from a variable input using PowerShell 4.0

前端 未结 5 1665
青春惊慌失措
青春惊慌失措 2021-02-05 03:59

I\'ve tried a few things already but they don\'t seem to work for some reason.

Basically what I\'m attempting to do is have a user input a value using the \"Read-host\

5条回答
  •  一整个雨季
    2021-02-05 04:32

    You can use:

    $answer.replace(' ' , '')
    

    or

    $answer -replace " ", ""
    

    if you want to remove all whitespace you can use:

    $answer -replace "\s", ""
    

提交回复
热议问题