Removing spaces from a variable input using PowerShell 4.0

前端 未结 5 1674
青春惊慌失措
青春惊慌失措 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:31

    If the string is

    $STR = 'HELLO WORLD'
    

    and you want to remove the empty space between 'HELLO' and 'WORLD'

    $STR.replace(' ','')
    

    replace takes the string and replaces white space with empty string (of length 0), in other words the white space is just deleted.

提交回复
热议问题