function sTb(str, charSet)
'''''''''''''''''''''''''''''
' 字符串转二进制函数
'
''''''''''''''''
' 参数说明
''''''''''
' str: 要转换成二进制的字符串
' charSet: 字符串默认编码集, 如不指定, 则默认为 gb2312
''''''''''
' sample call: response.binaryWrite sTb(str, "utf-8")
'''''''''''''''''''''''''''''
dim stm_
set stm_=createObject("adodb.stream")
with stm_
.type=2
if charSet<>"" then
.charSet=charSet
else
.charSet="gb2312"
end if
.open
.writeText str
.Position = 0
.type=1
sTb=.Read
.close
end with
set stm_=nothing
end function
function bTs(str, charSet)
'''''''''''''''''''''''''''''
' 二进制转字符串函数
'
''''''''''''''''
' 参数说明
''''''''''
' str: 要转换成字符串的二进制数据
' charSet: 字符串默认编码集, 如不指定, 则默认为 gb2312
''''''''''
' sample call: response.write bTs(midB(sTb(str, "utf-8"),1),"utf-8")
'''''''''''''''''''''''''''''
' 注意: 二进制字符串必须先用 midB(binaryString,1) 读取(可自定读取长度).
'''''''''''''''''''''''''''''
dim stm_
set stm_=createObject("adodb.stream")
with stm_
.type=2
.open
.writeText str
.Position = 0
if charSet<>"" then
.CharSet = charSet
else
.CharSet = "gb2312"
end if
bTs=.ReadText
.close
end with
set stm_=nothing
end function
找了很久,主要是为了解决UTF-8下,SQL的IMAGE字段里的中文显示时乱码的问题.