简体   繁体   中英

Encoding special characters in c#

In my c# application, i receive post data in the form of xml. Within the xml i have a attribute receiving as " SmÃ¥senter (Sandvika SmÃ¥senter) " . Before inserting to database i need to encode it as " Småsenter (Sandvika Småsenter) " . I tried to use below code ,

string name = "Småsenter (Sandvika Småsenter)";
name = HttpUtility.HtmlDecode(name);

Also tried name = HttpUtility.HtmlEncode(name);

But it is not giving expected output. Is any suggessions to get in expected characters.

Regards

Sangeetha

You have just encountered Mojibake , which is caused by mixing text encodings. You need to use the same encoding for writing and reading the XML, preferably a Unicode encoding such as UTF-8. You should not try to repair a broken string such as "Småsenter", but rather make it not break in the first place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM