|
|
|
7i24.Com不停为您服务 在ASP/VBScript中用二进制数
ASP (VBS) has only basic support for binary data. The data can be
created and accessed by 'B' string functions (ChrB, MidB,
InStrB...) :
Dim i, MyByteArray
For i=1 To 255
MyByteArray = MyByteArray & ChrB(i)
Next
Response.Buffer = True
Response.ContentType = "Application/Crazzy"
Response.BinaryWrite MyByteArray
You can also create convert function from String to binary :
Function StringToBinary(S)
Dim i, ByteArray
For i=1 To Len(S)
ByteArray = ByteArray & ChrB(Asc(Mid(S,i,1)))
Next
StringToBinary = ByteArray
End Function
And use the function :
Response.BinaryWrite StringToBinary("My first binary string.")
You can work with binary data from BinaryRead by the same way :
Binary = Request.BinaryRead(Request.ServerVariables
("HTTP_Content_Length"))
bString = BinaryToString(Binary)
Response.Write bString
'Of course, you can use Response.BinaryWrite Binary :-)
Where BinaryToString is :
Function BinaryToString(Binary)
Dim I, S
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
BinaryToString = S
End Function
To save/retrieve binary data from disk, binary file upload and
download in ASP or better work with binary data (use different code
pages - ANSI, MAC, UTF, search binary data, etc.)
http://www.pstruh.cz/tips/detpg_BinASP.htm
|
|
|