本文介绍了如何在 PowerShell 中用 %20 替换空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个 PowerShell 脚本,它将根据用户输入组合一个 HTTP 路径.输出必须将用户输入中的任何空格转换为产品特定代码%2F".
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, "%2F".
这是源代码和输出的示例:
Here's a sample of the source and the output:
站点 URL 可以是常量,但变量是更好的重用方法,如程序中使用的:/http:%2F%2SPServer/Projects/"
The site URL can be a constant, though a variable would be a better approach for reuse, as used in the program is: /http:%2F%2SPServer/Projects/"
$Company="Company"
$Product="Product"
$Project="The new project"
$SitePath="$SiteUrl/$Company/$Product/$Project"
作为我需要的输出:
'/http:%2F%2FSPServer%2FProjects%2FCompany%2FProductF2FThe%2Fnew%2Fproject'
推荐答案
将 " "
替换为 %20
并将 /
替换为 %2F
等,执行以下操作:
To replace " "
with %20
and /
with %2F
and so on, do the following:
[uri]::EscapeDataString($SitePath)
这篇关于如何在 PowerShell 中用 %20 替换空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!