ByteArray - UrlDecode

Converts a URL-encoded byte array into a decoded string using the specified decoding object.

Try it

public static void Main()
{
    string urlString = "http%3a%2f%2ftest%23+space+123%2ftext%3fvar%3dval%26another%3dtwo";
	
	//C# Extension Method: String - ToByteArray
    var bytes = urlString.ToByteArray();
	
	//C# Extension Method: ByteArray - UrlDecode
	string output = bytes.UrlDecode(Encoding.UTF8);

    Console.WriteLine(output);
}

View Source
using System;
using System.Text;
#if !NETSTANDARD
using System.Web;
#endif

public static partial class Extensions
{
#if !NETSTANDARD
    /// <summary>
    ///     Converts a URL-encoded byte array into a decoded string using the specified decoding object.
    /// </summary>
    /// <param name="bytes">The array of bytes to decode.</param>
    /// <param name="e">The  that specifies the decoding scheme.</param>
    /// <returns>A decoded string.</returns>
    public static String UrlDecode(this Byte[] bytes, Encoding e)
    {
        return HttpUtility.UrlDecode(bytes, e);
    }

    /// <summary>
    ///     Converts a URL-encoded byte array into a decoded string using the specified encoding object, starting at the
    ///     specified position in the array, and continuing for the specified number of bytes.
    /// </summary>
    /// <param name="bytes">The array of bytes to decode.</param>
    /// <param name="offset">The position in the byte to begin decoding.</param>
    /// <param name="count">The number of bytes to decode.</param>
    /// <param name="e">The  object that specifies the decoding scheme.</param>
    /// <returns>A decoded string.</returns>
    public static String UrlDecode(this Byte[] bytes, Int32 offset, Int32 count, Encoding e)
    {
        return HttpUtility.UrlDecode(bytes, offset, count, e);
    }
#endif
}