ASP:我无法解码从utf-8到iso-8859-1的某些字符

And*_*ine 1 utf-8 asp-classic utf8-decode

我用这个函数来解码UTF-8:

function DecodeUTF8(s)
  dim i
  dim c
  dim n
  i = 1
  do while i <= len(s)
    c = asc(mid(s,i,1))
    if c and &H80 then
      n = 1
      do while i + n < len(s)
        if (asc(mid(s,i+n,1)) and &HC0) <> &H80 then
          exit do
        end if
        n = n + 1
      loop
      if n = 2 and ((c and &HE0) = &HC0) then
        c = asc(mid(s,i+1,1)) + &H40 * (c and &H01)
      else
        c = 191 
      end if
      s = left(s,i-1) + chr(c) + mid(s,i+n)
    end if
    i = i + 1
  loop

  DecodeUTF8 = s
end function
Run Code Online (Sandbox Code Playgroud)

但有一些问题可以解码这些字符:

€,ƒ"...†‡‰Š<OEZ '''’•--~™S>œžŸ

在这种情况下

C = 191 - > C = '¿'

我发现了一些与此问题相关的信息:http: //www.i18nqa.com/debug/utf8-debug.html

你知道任何正确解码的功能吗?

ull*_*ink 5

Public Function DecodeUTF8(s)
  Set stmANSI = Server.CreateObject("ADODB.Stream")
  s = s & ""
  On Error Resume Next

  With stmANSI
    .Open
    .Position = 0
    .CharSet = "Windows-1252"
    .WriteText s
    .Position = 0
    .CharSet = "UTF-8"
  End With

  DecodeUTF8 = stmANSI.ReadText
  stmANSI.Close

  If Err.number <> 0 Then
    lib.logger.error "str.DecodeUTF8( " & s & " ): " & Err.Description
    DecodeUTF8 = s
  End If
  On error Goto 0
End Function
Run Code Online (Sandbox Code Playgroud)