Should I change from UTF-8 to UTF-16 to accommodate Chinese characters in my HTML?

爷,独闯天下 提交于 2019-12-09 09:46:05

问题


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


回答1:


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, 3, up to a max of 4 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.




回答2:


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.



来源:https://stackoverflow.com/questions/3864842/should-i-change-from-utf-8-to-utf-16-to-accommodate-chinese-characters-in-my-htm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!