How do I replace spaces with in PowerShell?

前端 未结 4 1603
终归单人心
终归单人心 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:26

    The output transformation you need (spaces to %20, forward slashes to %2F) is called URL encoding. It replaces (escapes) characters that have a special meaning when part of a URL with their hex equivalent preceded by a % sign.

    You can use .NET framework classes from within Powershell.

    [System.Web.HttpUtility]::UrlEncode($SitePath) 
    

    Encodes a URL string. These method overloads can be used to encode the entire URL, including query-string values.

    http://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode.aspx

提交回复
热议问题