以下是创建zip文件并向其中添加文件的代码。
问题:当前,当创建zip文件时,其中包含的文件包含
问题:当前,当创建zip文件时,其中包含的文件包含
%20
而不是空格,这是一种功能。我还有另一个要求,即将%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.Replace。
编辑:哦 - 您可以使用EscapeDataString将%20放入字符串中。至于正则表达式方法,您可以尝试
Regex encodeSpace = new Regex(" "]);
然后您可以在字符串上调用替换 string newStringWithNoSpaces = encodeSpace.Replace(oldString, "%20");
您可以为另一个方向执行类似操作。