/*From:http://blog.JoyCode.com/hopeq/archive/2005/09/26/64146.aspx*/
There is a web project. Requestencoding and Responsencoding are both GB2312 in Web.Config. The profile data taken from the database may be mixed with Chinese, Korean and Japanese. The Korean content cannot be displayed correctly. Of course, if the coding of the project uses UTF-8, there will be no problem, but this project is an old project. In order not to affect the existing program, it is impossible to change the encoding to UTF-8 and can only move on this page Brain.
After research, it is found that this problem can be solved by the HTML entity method.
For HTML entities, please refer to:
Character Entity References in HTML 4
html document replaceivity
Test code:
byte [] bcomments = encoding.utf8.getbytes ("ich is ブ ル ???? Chinese");
char [] ccomments = enCoding.utf8.getchars (bcomments);
StringBuilder Charbuilder = New StringBuilder ();
Foreach (Char C in CCOMMENTS)
{{
if (c> '/u0800'))
{{
charBuilder.append ("&#");
charBuilder.append ((int) c);
}
else
{{
charBuilder.append (C);
}
}
response.write (charBuilder.tostring ());
The role of this code is to output all Chinese, Korean, and Japanese characters into HTML entities through hard coding. The HTML entity is not affected by the refonsencoding and page coding set.
illustrate:
/U0800 above is Chinese, Korean, and Japanese characters.
Scope of Chinese:/U4E00-/U9FA5, Japanese in/U0800-/U4E00, and Korean is above/U9FA5.
This method is just to solve the small -scale problem. If you have a better way, please advise.