I've a RFC 3986 encoded string in the form %x##. For example the space character is encoded as %x20 instead of %20. How can I decode it in C#?
Using the decode method of Uri, HttpUtility or WebUtility classes the string was not decoded.
How unescape RFC 3986 string
395 Views Asked by Matteo At
2
There are 2 best solutions below
0
On
You can try something like this: You can try:
Reference: How to get Uri.EscapeDataString to comply with RFC 3986
var escapedString = new StringBuilder(Uri.EscapeDataString(value));
for (int i = 0; i < UriRfc3986CharsToEscape.Length; i++) {
escapedString.Replace(UriRfc3986CharsToEscape[i], Uri.HexEscape(UriRfc3986CharsToEscape[i][0]));
}
// Return the fully-RFC3986-escaped string.
return escaped.ToString();
You can try regular expressions in order to
Replaceall%x##as well as%##matches:Outcome: