首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

asp怎么检测文本文件的编码方式,主要想区分Ansi和UTF-8

2012-07-31 
asp如何检测文本文件的编码方式,主要想区分Ansi和UTF-8网络上的下面这段代码检测有误,还是我使用有误%fil

asp如何检测文本文件的编码方式,主要想区分Ansi和UTF-8
网络上的下面这段代码检测有误,还是我使用有误
<%
filePathName = Server.MapPath("/index.asp")
Response.write checkcode(filePathName)
Function checkcode(path) 
 Set objstream = server.createobject("adodb.stream") 
 objstream.Type = 1 
 objstream.mode = 3 
 objstream.open 
 objstream.Position = 0 
 objstream.loadfromfile path 
 bintou = objstream.read(2) 
 If AscB(MidB(bintou,1,1))=&HEF And AscB(MidB(bintou,2,1))=&HBB Then 
  checkcoder="utf-8" 
 ElseIf AscB(MidB(bintou,1,1))=&HFF And AscB(MidB(bintou,2,1))=&HFE Then 
  checkcode="unicode" 
 Else 
  checkcode="gb2312"
 End If 
 objstream.close
 Set objstream = nothing 
End Function
%>

[解决办法]
我检测是对的,代码是好的~~~

不知道你那里报什么错~~~?
[解决办法]
代码看上去是对的。
用UltraEdit之类的工具打开asp文件,用Hex方式查看前2个字节是不是 EF BB 就知道是不是 UTF-8编码了

热点排行
Bad Request.