Mohanapriya R Mohanapriya R
Updated date Jul 30, 2024
In this article, we will explore the fundamentals of HTML decoding in C#. Learn how to convert HTML-encoded strings to their original form, ensuring a seamless and secure user experience in your web applications.

Convert Strings to HTML Decode in Cin C#

In C#, you can use the System.Net.WebUtility class to decode HTML entities. The HtmlDecode method within this class is specifically designed for this purpose.

using System;

class Program
{
    static void Main()
    {
        // Sample HTML-encoded string
        string encodedString = "Hello <World>";

        // Decode the HTML-encoded string
        string decodedString = System.Net.WebUtility.HtmlDecode(encodedString);

        // Display the original and decoded strings
        Console.WriteLine("Original String: " + encodedString);
        Console.WriteLine("Decoded String : " + decodedString);
    }
}

We have defined an HTML-encoded string ("Hello <World>"). Using WebUtility.HtmlDecode, we decoded this string and store the result in another variable (decodedString).

Output:

Original String: Hello <World>
Decoded String : Hello <World>

 

Comments (0)

There are no comments. Be the first to comment!!!