.net中中文乱码问题解决

类别:Asp 点击:0 评论:0 推荐:

        asp.net默认的编码为utf-8,当与其它平台交互处理的字符串中有中文时往往会出现乱码,这是由于其它平台多采取GB2312编码,要解决这一问题,可编写一个函数,对字符串先转换再处理就行了,下面是该函数的源代码:

Imports System.Math

 Function URLEncoding(ByVal vstrIn As String)
        Dim strReturn As String
        strReturn = ""
        Dim i As Integer

        Dim ThisChr As String

        Dim innerCode, Hight8, Low8 As Integer

        For i = 1 To vstrIn.Length

            ThisChr = Mid(vstrIn, i, 1)

            If Abs(Asc(ThisChr)) < &HFF Then
                strReturn = strReturn & ThisChr
            Else
                innerCode = Asc(ThisChr)
                If innerCode < 0 Then
                    innerCode = innerCode + &H10000
                End If
                Hight8 = (innerCode And &HFF00) \ &HFF
                Low8 = innerCode And &HFF
                strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
            End If
        Next
        URLEncoding = strReturn
    End Function

本文地址:http://com.8s8s.com/it/it8797.htm