Reputation: 1427
I am trying to convert unicode character in c# but it is not working
code:
using System;
using System;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace test_request
{
class MainClass
{
public static void Main (string[] args)
{
string unicode = "Not Your Boyfriend's Tunic";
string str = System.Uri.UnescapeDataString(unicode);
Console.WriteLine (str);
}
}
}
Ouput:
Not Your Boyfriend's Tunic
But expected output is this
Expected output:
Not Your Boyfriend's Tunic
Upvotes: 1
Views: 793
Reputation: 994
Both solutions will work for you:
Using Server.HtmlDecode:
string unicode = "Not Your Boyfriend's Tunic";
string str = Server.HtmlDecode(unicode);
Console.WriteLine (str);
reference link: This MSDN document.
Using HttpUtility.HtmlDecode: hello
string unicode = "Not Your Boyfriend's Tunic";
string str = HttpUtility.HtmlDecode(unicode);
Console.WriteLine (str);
reference link: This MSDN document.
Difference between both:
Both does same work but the only difference is: Server.HtmlDecode() is readily availalble at runtime from a web page whereas HttpUtility.HtmlDecode() is a static method that can be used from anywhere.
Upvotes: 2
Reputation: 1241
try this
using System;
using System;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace test_request
{
class MainClass
{
public static void Main (string[] args)
{
string unicode = "Not Your Boyfriend's Tunic";
string str = System.Web.HttpUtility.HtmlDecode(unicode);
Console.WriteLine (str);
}
}
}
Upvotes: 2
Reputation: 1030
Use below function:
HttpUtility.HtmlDecode("Not Your Boyfriend's Tunic");
HttpUtility.HtmlEncode("Not Your Boyfriend's Tunic");
Upvotes: 3