【发布时间】:2016-06-24 04:02:08
【问题描述】:
以下是创建 zip 文件并向其添加文件的代码。
问题:目前,当创建 zip 文件时,其中存在的文件包含
%20而不是space,这是一个功能。我还有另一个要求是将%20替换为space。如何在下面的代码中实现这一点。
从帖子中删除了代码。
【问题讨论】:
以下是创建 zip 文件并向其添加文件的代码。
问题:目前,当创建 zip 文件时,其中存在的文件包含
%20而不是space,这是一个功能。我还有另一个要求是将%20替换为space。如何在下面的代码中实现这一点。
从帖子中删除了代码。
【问题讨论】:
这是一个使用Uri 静态类的示例:
var url = "http://www.somewhere.net/Thingy%20World.html";
var decoded = Uri.UnescapeDataString(url);
//decoded is currently 'http://www.somewhere.net/Thingy World.html'
var encoded = Uri.EscapeUriString(decoded);//back to encoded
//encoded is currently 'http://www.somewhere.net/Thingy%20World.html'
【讨论】:
这应该会有所帮助:
https://msdn.microsoft.com/en-us/library/system.uri.unescapedatastring.aspx
取消转义数据字符串将是一种简单的方法。您还可以查看 Regex 和 Regex.Replace。
编辑:哦 - 您可以使用 EscapeDataString 将 %20 放入字符串中。至于正则表达式方法,您可以尝试
Regex encodeSpace = new Regex(" "]); 然后你可以在你的字符串上调用一个替换 string newStringWithNoSpaces = encodeSpace.Replace(oldString, "%20"); 你可以在另一个方向上做类似的事情。
【讨论】: