Using the ADODB.stream object to convert a stream of bytes into a character streams in ASP

Source: Internet
Author: User
'--------------------------------------------------------------------
' Binary spin string
'
' Entry parameters: byte stream
' function return: string
' Code By:madpolice 2002-12-20
' Use ADODB. Stream object, which is faster than the original character substitution method n times, n≈30!!
'--------------------------------------------------------------------
' The following constants are used by the function, because I've already defined outside the function, so I'm not here to repeat the definition
'----streamtypeenum Values----
' Const adTypeBinary = 1
' Const adTypeText = 2
Function Bytes2bstr (VIN)
Dim Bytesstream,stringreturn
Set Bytesstream = Server.CreateObject ("ADODB. Stream ")" to create a stream object
With Bytesstream
. Type = adTypeText ' Sets the stream object to be of character streams
. Open ' opens the Stream object
. WriteText Vin ' writes Vin to the inflow object
. Position = 0 ' Sets the starting position of the stream object to be 0, which is the beginning
' This operation must be done, and why I do not know, failed n times to come to the conclusion
' If you do not do this, there is an error setting the CharSet property
. Charset = "GB2312" ' Sets the encoding method for the stream object to be GB2312
. Position = 2 ' Sets the starting position of the stream object to be 2 (filter out the beginning of a control character
' This control character is the WriteText method charset= ' Unicode ' by default property
' The data is automatically added to the beginning of the data, the value of the character is ff3f
' This control character occupies 2 bytes, so position is set to 2
' Represents an abbreviated 2 byte, the following ReadText method reads data from position
Stringreturn =. ReadText ' Saves the contents of the stream object in the Stringreturn variable
. Close ' Closes the stream object
End With
Set Bytesstream = Nothing ' Destroy Stream object
Bytes2bstr = Stringreturn
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.