- 本站大部分内容从网上收集,收集目的仅供研究、学习。涉及版权或不希望收录您的文章请您及时与我联系。
- 本站IM群,请自行选择。请各位朋友按照自己喜好加入。加入群后请及时发言,防止被清理。谢谢您的合作!!!
- QQ群:Y①WEB开发(ASP.NET)号码:7351660 QQ群:Y②WEB开发(ASP+.NET)号码:11864905
- QQ群:Y③WEB开发(DIV+CSS)号码:16610506 QQ群:Y④WEB开发(JS+AJAX)号码:16143998
- QQ群:Y⑤WEB开发(新手)号码:12777715 MSN群:yaosansi[at]126.com
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";
}
范例:
switchLanguage(Request.UserLanguages[0]);
但有些GB2312简体字没有对应的Big5,所以需要先转换成繁体的Gb2312,再进行转换
如:“秋水无恨”的无,“中国”的国,就会显示“秋水?恨”和“中?”
等需要先转化为“秋水無恨”和“中國”,再转化为Big5。
而filter正好帮助我们实现实时切换,主要源代码如下(_sGB和_tGB是GB2312简繁体对应的库)。
public override void Write(byte[] buffer, int offset, int count)
{
Encoding e=Encoding.GetEncoding(936);
string str=e.GetString(buffer,offset,count);
for(int i=0;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));
}
范例:
<%@ Page Language="C#" %>
hi,你好,我是
ps.如果web.config中有
可省略
Response.ContentEncoding=Encoding.GetEncoding(936);
cs 源代码和dll:
点击下载此文件dll直接拷到应用程序的bin目录即可调用
订阅本站,阅读更多文章