How do I replace spaces with in PowerShell?

前端 未结 4 1621
终归单人心
终归单人心 2020-12-29 18:47

I\'m creating a PowerShell script that will assemble an HTTP path from user input. The output has to convert any spaces in the user input to the product specific codes, \"%2

4条回答
  •  醉酒成梦
    2020-12-29 19:27

    The solution of @manojlds converts all odd characters in the supplied string. If you want to do escaping for URLs only, use

    [uri]::EscapeUriString($SitePath)
    

    This will leave, e.g., slashes (/) or equal signs (=) as they are.

    Example:

    # Returns http%3A%2F%2Ftest.com%3Ftest%3Dmy%20value
    [uri]::EscapeDataString("http://test.com?test=my value")
    
    # Returns http://test.com?test=my%20value
    [uri]::EscapeUriString("http://test.com?test=my value") 
    

提交回复
热议问题