我应该从UTF-8更改为UTF-16以在HTML中容纳汉字吗? [英] Should I change from UTF-8 to UTF-16 to accommodate Chinese characters in my HTML?
问题描述
我正在使用ASP.NET MVC,MS SQL和IIS.我有一些在个人资料信息中使用汉字的用户.但是,当我显示此信息时,其显示为æŽå¼·è¯
,但在我的数据库中它们是正确的.目前,我将HTML页面的UTF设置为UTF-8.我应该将其更改为UTF-16吗?我了解有一个一些问题可能由此产生,但是我有什么选择?
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?
谢谢
亚伦
推荐答案
UTF-8和UTF-16编码完全相同的一组字符.并不是说UTF-8不会覆盖汉字,而UTF-16不会覆盖汉字. UTF-16统一使用16位代表一个字符;而UTF-8使用1、2、3(最多4个字节),具体取决于字符,因此ASCII字符仍表示为1个字节. 从此Wikipedia文章开始,以了解其背后的想法.
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.
因此,切换到UTF-16几乎不会对您有任何帮助.正如您在上面链接的SO问题中所讨论的那样,这有可能使情况变得更糟.您的设置中的其他地方存在问题,该问题未正确考虑非ASCII或非拉丁1字符.确保设置的每个部分都可以在UTF-8中使用.
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.
这篇关于我应该从UTF-8更改为UTF-16以在HTML中容纳汉字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!