专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

vb与vb.net得到汉字ASC的函数,该怎么解决

发布时间:2011-06-23 15:57:41 文章来源:www.iduyao.cn 采编人员:星星草
vb与vb.net得到汉字ASC的函数
将vb写的函数改写成vb.net的函数,得到的结果不一样
vb的函数如下:
Private   Sub   PackBytes(ByteArray()   As   Byte,   ByVal   PostData   As   String)
Dim   iNewBytes   As   Integer
Dim   i   As   Integer,   j   As   Integer,   ch   As   String
Dim   strHex   As   String

        iNewBytes   =   LenB(StrConv(PostData,   vbFromUnicode))   -   1
        If   iNewBytes   <   0   Then   Exit   Sub
       
        ReDim   ByteArray(iNewBytes)   As   Byte
        For   i   =   0   To   Len(PostData)   -   1
                ch   =   Mid(PostData,   i   +   1,   1)
                If   ch   =   " "   Then
                        ch   =   "+ "
                        ByteArray(j)   =   Asc(ch)
                ElseIf   Asc(ch)   <   0   Then
                        ByteArray(j)   =   CByte( "&H "   &   Left(Hex(Asc(ch)),   2))
                        j   =   j   +   1
                        ByteArray(j)   =   CByte( "&H "   &   Right(Hex(Asc(ch)),   2))
                Else
                        ByteArray(j)   =   Asc(ch)
                End   If
                j   =   j   +   1
        Next
End   Sub

vb.net的函数如下:
Private   Sub   PackBytes(ByVal   ByteArray()   As   Byte,   ByVal   PostData   As   String)
                Dim   iNewBytes   As   Integer
                Dim   i   As   Integer,   j   As   Integer,   ch   As   String
                'Dim   strHex   As   String

                iNewBytes   =   System.Text.Encoding.Default.GetBytes(PostData).Length   -   1
                If   iNewBytes   <   0   Then   Exit   Sub

                ReDim   ByteArray(iNewBytes)
                For   i   =   0   To   Len(PostData)   -   1
                        ch   =   Mid(PostData,   i   +   1,   1)
                        If   ch   =   " "   Then
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: