日期:2012-11-30  浏览次数:21108 次

'普通字符串转换成二进制字符串函数
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