天天看點

asp.net mysql 中文亂碼_asp.net中中文亂碼問題

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