VladZ
VladZ

Reputation: 11

How to convert diacritical words to text in browser using C# .NET (UTF-8/Unicode)?

The Web Page I work on, for example, takes the county from where a certain person sends feedback (because the site is an ad site, like ebay or aliexpress) and appears in an NPS (Net Promoter Score (NPS) is a customer loyalty and satisfaction measurement taken from asking customers how likely they are to recommend your product or service to others on a scale of 0-10) . In the database, for example, the county appears correctly written with diacritics, but when it is also displayed in browsers on the NPS page (the page where only the admin can see what review the user gave, where he is from, and what product category he was referring to), the special letters such as á, appears as á

When I try to add Hungarian words such as Állat, növény in the browser, special letters (Á, ö, é, etc.) appear with "Á" , ö, é, á. I tried different options looking for and reading among other similar situations, but none of them were useful for me to have those special letters in my browser. Below I will attach the code used. Thank you very much in advance for your help!

Could it be a problem elsewhere? At the server, the database, or somewhere else that I'm not aware of?

UPDATE: I tried to use HttpUtility.HtmlDecode but it didn't work

In the applicationUser.County are the words that contain different special letters

    //The first option I tried

    //byte[] utf8Bytes = Encoding.UTF8.GetBytes(applicationUser.County);
    //string str1 = Encoding.UTF8.GetString(utf8Bytes);

    //The second option I tried

    Encoding iso = Encoding.GetEncoding("ISO-8859-2");
    Encoding utf8 = Encoding.UTF8;
    byte[] utfBytes = utf8.GetBytes(applicationUser.County);
    byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
    string msg = iso.GetString(isoBytes);
    County = msg;

    //The third option I tried

    //string msg = HttpUtility.HtmlDecode(HttpUtility.HtmlDecode(applicationUser.County));

Here is a picture of the result I get in that NPS enter image description here

Upvotes: 0

Views: 183

Answers (0)

Related Questions