28,390
社区成员
发帖
与我相关
我的任务
分享
Function GetBytes(str, cSet)
With CreateObject("ADODB.Stream")
.Mode = 3
.Type = 2 ' 设为文本模式。 1 二进制 2 文本
.Open
.Charset = cSet ' 指定读写使用的字符集
.WriteText str ' 写入文本
.Position = 0
.Type = 1 ' 改成二进制模式 需注意的是:切换Type时,Position必须是0
GetBytes = .Read(-1) ' 读出 byte 数组
.Close
End With
End Function
Dim str, bytes
str = "ab中国人"
bytes = GetBytes(str, "GBK")
MsgBox TypeName(bytes)
MsgBox AscB(MidB(bytes, 1, 1)) ' 第一个 Byte
MsgBox AscB(MidB(bytes, 2, 1)) ' 第二个
MsgBox AscB(MidB(bytes, 3, 1)) ' 第三个
<%
' 数据存入 oStream (ADO Stream) 后
oStream.Position = 0
r = TransferFile(oStream, "application/octec-stream", "xxxx.bin")
Function TransferFile(ByRef oStream, sMimeType, sFilename)
Dim iChar, iSent, iSize
Dim c
Const FILE_TRANSFER_SIZE = 32768 '32k
iSent = 0
TransferFile = True
iSize = oStream.Size
With Response
.Charset = "GB2312"
.ContentType= sMimeType
.AddHeader "Accept-Ranges", "bytes"
.AddHeader "Content-Length", iSize
.AddHeader "Content-Type", sMimeType
.AddHeader "DownloadOptions", "noopen"
.AddHeader "Content-Disposition","attachment; filename=" & sFilename
End With
c = 0
Do While c <= iSize
iChar = oStream.Read(FILE_TRANSFER_SIZE)
c = c + FILE_TRANSFER_SIZE
With Response
.BinaryWrite(iChar)
iSent = iSent + FILE_TRANSFER_SIZE
If (iSent MOD FILE_TRANSFER_SIZE) = 0 Then
.Flush
If Not .IsClientConnected Then
TransferFile = False
Exit Do
End If
End If
End With
Loop
Response.Flush
If Not Response.IsClientConnected Then TransferFile = False
Set oStream = Nothing
End Function
%>