-1

I have a string that represents a uri escaped string.

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

%2F is need to be converted to '/'

%2B is need to be converted to '+'

%3D is need to be converted to '='

and etc.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Cod Fish
  • 917
  • 1
  • 8
  • 37

1 Answers1

4

Your string is not base64 encoded it's just uri escaped string. To unescape it you can use built in method from Uri object which is called 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

fubo
  • 44,811
  • 17
  • 103
  • 137
mrogal.ski
  • 5,828
  • 1
  • 21
  • 30