关于字符串转换问题,请各位帮个忙!

as2001 2006-10-10 12:07:39
有一个二进制数据,当我用 response.binarywrite SrcData 可以正常显示到页面,我尝试在网上搜索到一个转换函数

Function bin2str(binstr)
Dim varlen,clow,ccc,skipflag
skipflag=0
ccc = ""
If Not IsNull(binstr) Then
varlen=LenB(binstr)
For i=1 To varlen
If skipflag=0 Then
clow = MidB(binstr,i,1)
If AscB(clow) > 127 Then
ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
skipflag=1
Else
ccc = ccc & Chr(AscB(clow))
End If
ccc = ccc & Chr(AscB(clow))
Else
skipflag=0
End If
Next
End If
bin2str = ccc
End Function

用这个函数转换出来再用 response.write SrcData 打印到页面不正常,也许我没有转对,请大家帮个忙!谢谢!
...全文
237 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
muxrwc 2006-10-10
  • 打赏
  • 举报
回复
Dim Text: Text = replContent(BanaryCode, "gb2312")
muxrwc 2006-10-10
  • 打赏
  • 举报
回复
Function replContent(Content, CharCode)
Set obj = Server.CreateObject("Adodb.Stream")
With obj
.Type = 1
.Mode = 3
.Open()
.Write(Content)
.Position = 0
.Type = 2
.CharSet = CharCode
Dim nString
nString = .ReadText
.Close
End With
Set obj = Nothing
replContent = nString
End Function
as2001 2006-10-10
  • 打赏
  • 举报
回复
可以了,谢谢!!!马上结贴!
muxrwc 2006-10-10
  • 打赏
  • 举报
回复
500?
不支持Stream?
我用的就是那个啊。
把二进制转换成gb2312,好用啊。。
楼上的多。。你用他的试试。
明珠佩佩 2006-10-10
  • 打赏
  • 举报
回复
1. ascii 字符集 二进制流转字符串函数

<%
private function bTsAscii(bin)
'二进制转为 string (bmp|gif|png|jpg)
dim i, iByt, sByt, bLen:bLen=lenB(bin)
for i=1 to bLen
sByt=midB(bin,i,1):iByt=ascB(sByt)
if iByt<128 then
bTsAscii=bTsAscii&chr(iByt)
else:i=i+1
if i<=bLen then bTsAscii=bTsAscii&chr(ascW(sByt&sByt))
end if
next
end function
%>

2. gb2312 字符集 二进制流转字符串函数

<%
private function bTsGb2312(bin)
'二进制转为 string | gb2312 编码
dim i, iByt, sByt, bLen:bLen=lenB(bin)
for i=1 to bLen
sByt=midB(bin,i,1):iByt=ascB(sByt)
if iByt<128 then
bTsGb2312=bTsGb2312&chr(iByt)
else
bTsGb2312=bTsGb2312&chr(ascW(midB(bin,i+1,1)&sByt))
i=i+1
end if
next
end function
%>

3. adodb.stream 字符串转二进制流函数 与 二进制流转字符串函数 及演示操作

<%
dim str
str="adodb.stream 实现 二进制与字符串的互转"

response.write "字符串转二进制 response.binaryWrite sTb(str, ""utf-8""):<br/>"
response.binaryWrite sTb(str, "utf-8")

response.write "<p/>二进制转字符串 response.write bTs(midB(sTb(str, ""utf-8""),1),""utf-8"")<br/>"
response.write bTs(midB(sTb(str, "utf-8"),1),"utf-8")

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
%>
as2001 2006-10-10
  • 打赏
  • 举报
回复
楼上的方法怎么会出现500错误,或者是不支持呢?

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧