最近在做的广告系统中,碰到了一个问题,广告系统采用的UTF-8编码,而一些使用这套广告系统的频道页面使用的是GB2312编码。当然也有使用UTF-8编码的频道使用这套广告系统。
频道页面是通过嵌入类似如下的代码方式,来调用广告的。具体那个时间显示那个广告,或者那些广告组合是广告系统自己处理的。
< script type = " text/javascript " >
<!--
csdn_AD_Position_GroupID = " {f05ff3bf-246b-4d71-a101-b5d4ee3f6cd3} " ;
csdn_AD_Page_Url = document.location;
// -->
</ script >
< script type = " text/javascript " src = " http://ads.csdn.net/AD/Show_JavaScript_AD.js " >
</ script >
不同编码的页面、脚本之间互相引用,就会产生乱码的问题,解决方法就是统一成一种编码。
asp.net 中,如果要修改输出页面的编码,可以通过修改web.config中以下配置信息
< globalization requestEncoding ="utf-8" responseEncoding ="utf-8" />
以上只是修改整体的默认编码,如果只有某个页的编码需要修改,ASP.net 中则可以简单的使用下面代码:
Encoding gb2312 = Encoding.GetEncoding( " gb2312 " );
Response.ContentEncoding = gb2312;
在非ASP.net 应用中,可能你读到的数据是UTF-8编码,但是你要转换为GB2312编码,则可以参考以下代码:
string utfinfo = " document.write(/"alert('aa你好么??');/"); " ;
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);
![]()
当然,其他各种编码之间的转换,跟上述代码也类似的,就不描述了。
打印 | posted on 2005年5月19日 10:44 | Filed Under [ .net 编程心得 ] | 收藏本页 (百度搜藏)(QQ书签)(Live收藏)(Google书签)(Yahoo书签)(新浪ViVi)(搜狐网摘)(365Key网摘)(天极网摘)(博采网摘)(和讯网摘)
反馈
那个页面?? 不同的页面,可能会是不同的原因。
另外清除本地 Cookie 和 临时文件看看
如何将一个utf-8编码的页面内的表单填写的内容,送到gb2312的页面上去不出现乱码.
楼主写的在非ASP.net 应用,我不是很明白.请回复!
谢谢!
Encoding gb2312 = Encoding.GetEncoding("gb2312");
Response.ContentEncoding = gb2312;
具体放在什么位置呀。
Encoding gb2312 = Encoding.GetEncoding("gb2312");
Response.ContentEncoding = gb2312;
具体放在什么位置呀。(Page_Load里即可)
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);
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);
.net程序怎么样结合js实现"那个时间显示那个广告,显示几次,或者那些广告组合"
望指教,不慎感激!!!
我的邮箱是:utmostkeb@gmail.com
-->
char[] asciiChars = new char[gb2312.GetCharCount(asciiBytes, 0, asciiBytes.Length)-1]
.net程序怎么样结合js实现"那个时间显示那个广告,显示几次,或者那些广告组合"
望指教,不慎感激!!!
我的邮箱是:utmostkeb@gmail.com
中英文混合的如: "我们要2000年的DATA资料"
中英文混合的如: "我们要2000年的DATA资料"
ZYYUJQ#126.COM
这真是太好了, 但是为什末?
鎮ㄥソ锛侀潪甯告劅璋㈡偍鐨勬潵淇★紝鎴戝緢楂樺叴鑳芥湁鏈轰細甯姪鎮ㄣ€?
鎴戜滑寤鸿鎮ㄦ妸鍦≒aypal涓婁慨鏀规偍鐨勯摱琛屼俊鎭紝鍥犱负Paypal鏃犳硶鍚戦摱琛屽嚭绀轰换浣曡瘉鏄庢枃浠躲€?
鏀瑰彉閾惰璐︽埛璁剧疆鐨勮繃绋嬪涓嬶細
1锛夌櫥闄嗘偍鐨凱ayPal璐︽埛
2锛夎繘鍏モ€滅敤鎴蜂俊鎭€?3锛夌偣鍑烩€滈摱琛岃处鎴封€?4锛夐€夋嫨閿欒鐨勯摱琛屽笎鍙凤紝鐐光€滅Щ闄も€?5)鐐光€滄坊鍔犫€濓紝閲嶆柊娣诲姞姝g‘鐨勯摱琛岃处鎴枫€?
璇峰師璋呯粰鎮ㄥ甫鏉ョ殑璇稿涓嶄究銆傚鏋滄偍杩樻湁浠讳綍鐨勭枒闂紝璇峰洖澶嶆閭欢锛屼笌鎴戜滑鑱旂郴銆傞潪甯告劅璋㈡偍瀵筆ayPal涓€濡傛棦寰€鐨勬敮鎸併€?
Jovine
PayPal鍏ㄧ悆瀹㈡埗鏈嶅姟閮?