ANSI local coding, are defined by the countries themselves, there is no fixed file header format, in the mainland Chinese operating system, is readable gb2312, in other language system, is garbled, so this part does not need to distinguish in detail.
ANSI: no format definition
Unicode: The first two bytes are Fffe
Unicode big endian: first two bytes for Feff
Utf-8: first two bytes for 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
Principle: Using the Stream object to read the first two bytes of the file, analysis and determination of UTF-8, Unicode, ANSI (Simplified Chinese operating system, that is, gb2312) encoding.