怎样将GBK编码的数据转为UTF-8呢?

seajean 2008-09-17 10:08:58
小弟正在做紧一ASP程序..
需要加载外部的XML文档..
但是怎样可以将GBK编码的字符串为UTF-8编码然后输出呢??
在网上找了下但都是PHP下转换的?
或者怎样可以按照它原来的GBK编码输出呢?
只要不出现乱码就行...

...全文
216 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
seajean 2008-09-18
  • 打赏
  • 举报
回复

<%
function con(sstr)
dim str
set stm=server.CreateObject("adodb.stream")
stm.Type=2
stm.mode=3
stm.charset="GBK"
stm.open
stm.WriteText sstr
Stm.Position = 0
Stm.Type = 2
Stm.Charset = "utf-8"
str=stm.readtext
stm.Close
set stm=nothing
con=str
end function

Response.Buffer=True
Dim MyConnection, TheURL
TheURL = "http://kaifu163tech.blog.163.com/rss/"
Set MyConnection = Server.CreateObject("Microsoft.XMLHTTP")
MyConnection.Open "GET", TheURL, False
MyConnection.Send
TheData = MyConnection.responseText
Response.ContentType = MyConnection.getResponseHeader("Content-Type")
Response.Write con(TheData)
Set MyConnection = Nothing


response.write con(thedata)

%>



上边错啦..可是我用了这代码还是乱码啊..
大家帮我看下怎样才可以把我要输出的内容输出呢
seajean 2008-09-18
  • 打赏
  • 举报
回复

function con(sstr)
dim str
set stm=server.CreateObject("adodb.stream")
stm.Type=2
stm.mode=3
stm.charset="GBK"
stm.open
stm.WriteText sstr
Stm.Position = 0
Stm.Type = adTypeText
Stm.Charset = "utf-8"
str=stm.readtext
stm.Close
set stm=nothing
con=str
end function

Response.Buffer=True
Dim MyConnection, TheURL
TheURL = "http://kaifu163tech.blog.163.com/rss/"
Set MyConnection = Server.CreateObject("Microsoft.XMLHTTP")
MyConnection.Open "GET", TheURL, False
MyConnection.Send
TheData = MyConnection.responseText
Response.ContentType = MyConnection.getResponseHeader("Content-Type")
Response.Write con(TheData)
Set MyConnection = Nothing


response.write con(thedata)







我把读到的数据用这个函数

错误类型:
ADODB.Stream (0x800A0BB9)
参数类型不正确,或不在可以接受的范围之内,或与其他参数冲突。
proxy1.asp, 第 17 行
之后出现这样的错误了..请问为什么呢




xuStanly 2008-09-18
  • 打赏
  • 举报
回复
如果不能把GBK文档以UTF-8编码另存为,或者用转换工具批量转换,那就只有试一试4楼的办法了。
其它楼说的都只是声明当前文档的编码,而不是转换。
mrshelly 2008-09-18
  • 打赏
  • 举报
回复
ASP 可以使用 ADODB.Stream 进行转换。

具体可以查一下该组件的用法.

http://mrshelly.blogbus.com/logs/166141.html
hfdsoft 2008-09-17
  • 打赏
  • 举报
回复
Response.Charset = "utf-8"
seajean 2008-09-17
  • 打赏
  • 举报
回复
大家帮忙啊...
GBK是怎样的一样编码啊
为什么在CODEPAGE里无法设置呢?
seajean 2008-09-17
  • 打赏
  • 举报
回复
Response.ContentType = MyConnection.getResponseHeader("Content-Type")
为什么这一句不能实现...

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧