Home > Article > Backend Development > Chinese garbled problem in asp.net
The default encoding of asp.net is utf-8. When there is Chinese in the string that is processed interactively with other platforms, garbled characters often appear. This is because other platforms have many Adopt GB2312 encoding. To solve this problem, you can write a function to convert the string first and then process it. The following is the source code of the function:
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
The above is the detailed content of Chinese garbled problem in asp.net. For more information, please follow other related articles on the PHP Chinese website!