分类广告


推荐文章

  • 没有找到任何内容!
您当前的位置:中国站长下载网络编程ASP专区 → 文章内容

把普通字符串转换成二进制字符串的函数写出来了,和大家分享一下。

  • 作者:佚名    来源:不详    发布时间:2005-12-31 12:07:03
  • 字体大小:
'普通字符串转换成二进制字符串函数
Function Str2Bin(String)
  Dim i, tmpbin
  For i=1 to strLength(String)
    tmpbin = tmpbin & ChrB(Asc(Mid(String,I,1)))
  Next
  Str2Bin = tmpbin
End Function

'以下函数来自ChinaASP,计算字符串的真正字节数(支持中文)
Function strLength(str)
   If (len("飞鸟")=2) then
      Dim l,t,c,i
      l=Len(str)
      t=l
      For i=1 To l
         c=asc(mid(str,i,1))
         If c<0 Then
            c=c+65536
         End If
         ' asc对中文字符求出来的值可能为负数,
         ' 加上65536就可求出它的无符号数值
         ' -1在机器内是用补码表示的0xffff,
         ' 其无符号值为65535,65535=-1+65536
         ' 其他负数依次类推。
         If c>255 Then
            t=t+1
         End If
      Next
      strLength=t
   Else
      strLength=len(str)
   End If
End Function