【www.gdgbn.com--中文酷站】

ansi的本地编码,都是各国自己定义的,没有固定的文件头格式,在大陆中文操作系统下,是可读的gb2312,在其他语言的系统下,就是乱码,所以这部分没必要再详细区分。

ansi:无格式定义
unicode:前两个字节为fffe
unicode big endian:前两字节为feff
utf-8:前两字节为efbb

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

原理:用stream对象预读文件的头两个字节,分析判断出utf-8、unicode、ansi(简体中文操作系统,即gb2312)编码。

本文来源:http://www.gdgbn.com/kuzhan/26712/