国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Asp.net把UTF-8編碼轉(zhuǎn)換為GB2312編碼

最近在做的系統(tǒng)中,碰到了一個問題,交易系統(tǒng)采用的UTF-8編碼,而一些支持系統(tǒng)使用的是GB2312編碼。

不同編碼的頁面、腳本之間互相引用,就會產(chǎn)生亂碼的問題,解決方法就是統(tǒng)一成一種編碼。
asp.net 中,如果要修改輸出頁面的編碼,可以通過修改web.config中以下配置信息


<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
以上只是修改整體的默認(rèn)編碼,如果只有某個頁的編碼需要修改,ASP.net 中則可以簡單的使用下面代碼:


注:加到Page_Load()事件下面就可以了
Encoding gb2312 = Encoding.GetEncoding("gb2312");
Response.ContentEncoding = gb2312;
在非ASP.net 應(yīng)用中,可能你讀到的數(shù)據(jù)是UTF-8編碼,但是你要轉(zhuǎn)換為GB2312編碼,則可以參考以下代碼:

string utfinfo = "document.write(\"alert(‘你好么??‘);\");";
string gb2312info = string.Empty;

Encoding utf8 = Encoding.UTF8;
Encoding gb2312 = Encoding.GetEncoding("gb2312");

// Convert the string into a byte[].
byte[] unicodeBytes = utf8.GetBytes(utfinfo);
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(utf8, gb2312, unicodeBytes);
           
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[gb2312.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
gb2312.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
gb2312info = new string(asciiChars);

當(dāng)然,其他各種編碼之間的轉(zhuǎn)換,跟上述代碼也類似的,就不描述了。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
c# 字符串編碼問題
字符編碼問題摘要
asp.net URL參數(shù)加密解密的問題
struts2中文亂碼解決方法
java下URL參數(shù)帶中文的編碼問題
Tomcat關(guān)于encoding編碼的默認(rèn)設(shè)置以及亂碼產(chǎn)生的原因
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服