tags:

views:

45

answers:

2

I am using ASP.NET MVC, MS SQL and IIS. I have a few users that have used Chinese characters in their profile info. However, when I display this information is shows up as æŽå¼·è¯ but they are correct in my database. Currently my UTF for my HTML pages is set to UTF-8. Should I change it to UTF-16? I understand there are a few problems that can come from this but what are my choices?

Thank you,

Aaron

+2  A: 

Any UTF coding should work the same in their ability to represent Unicode characters so switching to UTF-16 wouldn't help. There's an encoding issue somewhere and with UTF-16 you would only end up with different wrong HTML representation. Of course if you have some library that simply encodes non-ASCII characters as entities and does support wide characters, your problem may be solved by the switch. There are however characters that need even 2 wide characters and these would still be shown wrong, although users might rarely notice. The best option would be to have whatever is producing the HTML to interpret your UTF-8 correctly.

jjrv
+1  A: 

UTF-8 and UTF-16 encode exactly the same set of characters. It's not that UTF-8 doesn't cover Chinese characters and UTF-16 does. UTF-16 uses uniformly 16 bits to represent a character; while UTF-8 uses 1, 2, or 3 bytes depending on the character, so that an ASCII character is represented still as 1 byte. Start with this Wikipedia article to get the idea behind it.

So, there's little chance switching to UTF-16 will help you at all. There's a chance it makes things worse, as is discussed in the SO question you linked above. There's a problem somewhere else in your setup, which does not correctly take into account non-ASCII or non-Latin-1 characters. Make sure every part of your setup works in UTF-8.

Yuji