[英]How to remove %20 from Uri in c#?
I want to remove %20
from file name but it should be in Uri format. 我想从文件名中删除%20
,但它应为Uri格式。
Dictionary<string, Uri> urilist = new Dictionary<string, Uri>();
string fileName="test data.txt";
Uri partUriDocument;
partUriDocument = PackUriHelper.CreatePartUri(new Uri(fileName, UriKind.Relative));
urilist.Add(fileName, partUriDocument);
partUriDocument contains test%20data.txt
. partUriDocument包含test%20data.txt
。
How to make it test data.txt
. 如何使其test data.txt
。
partUriDocument contains test%20data.txt. partUriDocument包含test%20data.txt。
How to make it test data.txt. 如何使其测试data.txt。
You can properly decode it using 您可以使用正确解码
var decodedFileName = WebUtility.UrlDecode(fileName); // returns "test data.txt"
What you want to do is called decoding. 您要执行的操作称为解码。 It's the same mecanic you're using when you go from 当您离开时使用的是相同的mecanic
string str = "123"; //String
int number = Int.Parse(str) // Decode string into a number
You encode your string in an uri, you decode your uri in a string 您将字符串编码为uri, 将您的uri 解码为字符串
Use Uri.Parse
使用Uri.Parse
var str = Uri.Parse(Uri);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.