以下是创建zip文件并向其添加文件的代码。
问题:目前,当创建zip文件时,其中包含的文件包含
%20
而不是space
,这是一项功能。我有另一项要求将%20
替换为{ {1}}。如何在下面的代码中实现这一点。
从帖子中删除了代码。
答案 0 :(得分:2)
以下是使用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'
答案 1 :(得分:0)
这应该有所帮助:
https://msdn.microsoft.com/en-us/library/system.uri.unescapedatastring.aspx
取消数据字符串将是一种简单的方法。您还可以查看Regex和Regex.Replace。
编辑:哦 - 你可以使用EscapeDataString将%20放入字符串中。至于Regex方法,你可以试试
Regex encodeSpace = new Regex(" "]);
然后你可以在你的字符串上调用替换string newStringWithNoSpaces = encodeSpace.Replace(oldString, "%20");
你可以为另一个方向做类似的事情。