检测文件编码格式

来源:互联网 发布:打字教学软件 编辑:程序博客网 时间:2024/05/17 03:44

ANSI:        无格式定义;
Unicode:        前两个字节为FFFE;
Unicode big endian:   前两字节为FEFF; 
UTF-8:         前两字节为EFBB;


ASP/Visual Basic代码
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