Recently, Asp-related files cannot be found on the Internet. If someone gets it out early, don't joke about it. After a long time, you can get it done;
Principle: Analyze and determine the UTF-8, Unicode, and ANSI (Simplified Chinese operating system (gb2312) encoding by using the first two bytes of the stream object pre-Read File.
Related Materials:
Supplement:
Xie Xiaoyu reminded me that the previous code is nonsense. ANSI's local code is defined by countries and does not have a fixed File Header Format. In Chinese operating systems in mainland China, It is readable gb2312, in systems in other languages, it is garbled, so this part does not need to be distinguished in detail.
After getting the file encoding, the stream can be opened according to the required encoding, so it will not be garbled.
ANSI: No format definition;
UNICODE: The first two bytes are fffe;
Unicode big endian: The first two bytes are feff;
UTF-8: The first two bytes are 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,) = & HFF and ASCB (midb (Bintou )) = & hfe then
checkcode = "Unicode"
else
checkcode = "gb2312"
end if
objstream. close
set objstream = nothing
end function