ASP detection file encoding

Source: Internet
Author: User
Tags format definition

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.