.NET Chinese garbled problem solved

xiaoxiao2021-03-06  85

ASP.NET default encoding is UTF-8, when there is Chinese in a string that interacts with other platforms, there is a garbled, which is due to other platforms to take GB2312 encoding, to solve this problem, can write a function, The string is first converted to process and then processes, the following is the source code of the function:

Imports system.mathfunction urlencoding (byval vstrin as string) Dim strreturn as string strreturn = "" DIM I as INTEGER

Dim thischr as string

Dim Innercode, High8, 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 = strreturnend function

转载请注明原文地址:https://www.9cbs.com/read-121991.html

New Post(0)