简体   繁体   English

从uri转义字符串转换为原始字符串(C#)

[英]Convert from uri escaped string to original characters string (C#)

I have a string that represents a uri escaped string. 我有一个表示uri转义字符串的字符串。

I want to convert it to original characters string. 我想将其转换为原始字符串。

For example: 例如:

6B%2FdHJaYVYZ9%2BkbVbNwB%2FmxPXwJhzmfIC8aUWOg%2F2mFCWzyrXaRHFsYLZSVedck3UW3FppuUG0jn2f4JMVUx9Q%3D%3D

is needed to be converted to: (Desired output) 需要转换为:(所需输出)

6B/dHJaYVYZ9+kbVbNwB/mxPXwJhzmfIC8aUWOg/2mFCWzyrXaRHFsYLZSVedck3UW3FppuUG0jn2f4JMVUx9Q==

The convertion is written here: http://www.w3schools.com/tags/ref_urlencode.asp 转换写在这里: http : //www.w3schools.com/tags/ref_urlencode.asp

%2F is need to be converted to '/' 必须将%2F转换为'/'

%2B is need to be converted to '+' 必须将%2B转换为“ +”

%3D is need to be converted to '=' 必须将%3D转换为'='

and etc. 等等。

Your string is not base64 encoded it's just uri escaped string. 您的字符串不是base64编码的,只是uri转义的字符串。 To unescape it you can use built in method from Uri object which is called UnescapeDataString : 要取消转义,可以使用Uri对象中的内置方法,即UnescapeDataString

string uriString = "6B%2FdHJaYVYZ9%2BkbVbNwB%2FmxPXwJhzmfIC8aUWOg%2F2mFCWzyrXaRHFsYLZSVedck3UW3FppuUG0jn2f4JMVUx9Q%3D%3D"
string unescaped = Uri.UnescapeDataString(uriString);
Assert.AreEqual("6B/dHJaYVYZ9+kbVbNwB/mxPXwJhzmfIC8aUWOg/2mFCWzyrXaRHFsYLZSVedck3UW3FppuUG0jn2f4JMVUx9Q==", unescaped);

Online example 在线示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM