ASP常用函数:Bytes2BStr()

<%
 
'功能:转换字符串编码
 
Function Bytes2BStr(Body, CSet)
 
    Dim oStream
 
    Set oStream = Server.CreateObject("ADODB.Stream")
 
    oStream.Type = 1
 
    oStream.Mode = 3
 
    oStream.Open
 
    oStream.Write Body
 
    oStream.Position = 0
 
    oStream.Type = 2
 
    oStream.Charset = CSet
 
    Bytes2BStr = oStream.ReadText
 
    oStream.Close
 
    Set oStream = Nothing
 
End Function
 
%>
 
  
 
<%
 
'功能:转换字符串编码
 
Function BytesToBStr(vIn)
 
    Dim strReturn
 
    Dim i, ThisCharCode, NextCharCode
 
    strReturn = ""
 
    For i = 1 To LenB(vIn)
 
        ThisCharCode = AscB(MidB(vIn, i, 1))
 
        If ThisCharCode < &H80 Then
 
            strReturn = strReturn & Chr(ThisCharCode)
 
        Else
 
            NextCharCode = AscB(MidB(vIn, i + 1, 1))
 
            strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
 
            i = i + 1
 
        End If
 
    Next
 
    BytesToBStr = strReturn
 
End Function
 
%>

其中Bytes2BStr效率比BytesToBStr高多了。

About 智足者富

http://chenpeng.info

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>