ASP:我无法将某些字符从 utf-8 解码为 iso-8859-1 [英] ASP: I can´t decode some character from utf-8 to iso-8859-1
本文介绍了ASP:我无法将某些字符从 utf-8 解码为 iso-8859-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这个函数来解码 UTF-8:
I use this function to 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
但是解码这些字符有一些问题:
But there are some probles to decode that characters:
€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’"•–~™š›œžŸ
€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’""•–—˜™š›œžŸ
这样的话
c=191-->c='¿'
c=191-->c='¿'
我发现了一些与此问题相关的信息:http://www.i18nqa.com/debug/utf8-debug.html
I found some info related with this problem: http://www.i18nqa.com/debug/utf8-debug.html
你知道正确解码的函数吗?
Do you know any function to decode correctly?
推荐答案
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
这篇关于ASP:我无法将某些字符从 utf-8 解码为 iso-8859-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文