Generating files in UTF-8 format with ASP

Source: Internet
Author: User
Tags character set control characters

ASP because it is an ancient language, some of its functions for UTF-8 support is very poor.
For example, you want to generate a file in UTF-8 format, using commonly used scrīpting. FileSystemObject object is no good.
Scripting. The FileSystemObject object creates a file function, which is the following:
Filesystemobject.createtextfile (Filename[,overwrite[,unicode]])
The Unicode properties are described in this way:
Options available. A Boolean value that indicates whether the file is created in Unicode or ASCII file format. True If the file is created in a Unicode file format, False if the file is created in an ASCII file format. If this section is omitted, the ASCII file is assumed to be created.
We cannot use this function to create a UTF-8 format file.
At this time, we can use ADODB. Stream object, using the method see below:

Set objstream = Server.CreateObject ("ADODB. Stream ")


with Objstream


. Open


. Charset = "Utf-8"


. Position = Objstream.size


. Writetext=str


. SaveToFile Server.MapPath ("/sitemap.xml"), 2


. Close


End With


Set objstream = Nothing


with:
ASCII, Unicode, UTF-8 Introduction:
ASCII is a character set, including uppercase and lowercase letters, numbers, control characters, etc., which are expressed in one byte, and the range is 0-127.

Because of the very limited number of characters represented in ASCII, each country or region proposes its own character set on this basis, such as the widely used GB2312 in China, which provides encoding for Chinese characters, expressed in two bytes.

These character sets are incompatible, and the same number may represent different characters, causing trouble with the exchange of information.
Unicode is a character set that maps all the characters in the world to a unique number (code point), such as a digital 0x0041 corresponding to the letter A. At present, Unicode is still in development, it contains more and more characters. The

also requires a certain encoding, such as UCS-2, to represent Unicode-encoded characters in two bytes when storing characters that are represented by Unicode. And UTF-8 is another encoding of the Unicode character set, it is variable length, up to 6 bytes, less than 127 characters in a byte, and the result of the ASCII character set, which is very good compatibility, ASCII-encoded English text without modification can be used as a UTF -8 code processing, the application is very extensive.

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.