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
以上是asp.net中中文亂碼問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!