Switch BIG5 and GB2312, and GB2312 simplified bodies using Filter

zhaozj2021-02-16  47

Previously solved the practice of GB2312 / BIG5 real-time conversion is generally modified response.contentencoding

string switchLanguage (String strLanguage) {if (strLanguage.StartsWith ( "zh-cn")) {Response.ContentEncoding = Encoding.GetEncoding (936); return "gb2312";} if (strLanguage.StartsWith ( "zh")) { Response.ContenTencoding = encoding.getencoding (950); return "big5";} response.contentencoding = encoding.getencoding (1252); Return "ISO-8859-1";

Example: SwitchLanguage (Request.userLanguages ​​[0]); But some GB2312 simple words have no corresponding BIG5, so it is necessary to convert into traditional GB2312, and then convert, "Qiu Water has no hate", "China" country, Will display "Autumn Water? Hate" and "?" And so on need to be transformed into "Autumn Water Sailing" and "China", and then transform into BIG5.

Filter just helped us to achieve real-time switching, the main source code is as follows (_sgb and _tgb is the GB2312 simple body corresponding to the library).

Public override void write (byte, int count) {encoding e = encoding.getencoding (936); string str = E.GETSTRING (Buffer, Offset, Count); for (int i = 0; i < Str.Length; I ) {INT j = _sgb.indexof (STR [i]); if (j! = - 1) str = str.replace (_SGB [J], _ TGB [J]);} E = Encoding. GetEncoding (System.Web.httpContext.current.response.charset); _sink.write (E.GETBYTES (STR), 0, E.GETBYTECOUNT (STR));}

example:

<% @ Page language = "c #"%>