ASP:我不能去code一些字符从UTF-8到ISO-8859-1 [英] ASP: I can´t decode some character from utf-8 to iso-8859-1

查看:122
本文介绍了ASP:我不能去code一些字符从UTF-8到ISO-8859-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用此功能去code UTF-8:

函数德codeUTF8(S)
  我朦胧
  尺寸C
  昏暗的ñ
  I = 1
  做,而我< = LEN(S)
    C = ASC(MID(S,I,1))
    如果C和放大器;然后H80
      N = 1
      做而I + N<镜片)
        如果(ASC(MID(S,I + N,1))和放大器; HC0)LT;> &安培;然后H80
          做出口
        万一
        N = N + 1
      循环
      如果n = 2和((C和放大器; HE0)=安培; HC0)然后
        C = ASC(MID(S,I + 1,1))+&安培; H40 *(c和&安培; H01)
      其他
        C = 191
      万一
      S =左(S,I-1)+ CHR(C)+中期(S,I + N)
    万一
    I = I + 1
  循环  德codeUTF8 = S
最终功能

但也有一些probles脱code的字符:


  

€,ƒ...†‡‰ŠœžŸ


在这种情况下


  

C = 191 - > C ='¿


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

你知道任何功能,取消code正确?


解决方案

公共职能德codeUTF8(S)
  设置stmANSI =的Server.CreateObject(的ADODB.Stream)
  S = S&安培;
  在错误恢复下一页  随着stmANSI
    。打开
    .POSITION = 0
    .CharSet =视窗1252
    .WriteText小号
    .POSITION = 0
    .CharSet =UTF-8
  结束与  德codeUTF8 = stmANSI.ReadText
  stmANSI.Close  如果错误的Err.number<> 0,则
    lib.logger.errorstr.De codeUTF8(与& S&安培;):&放大器; Err.Description它将
    德codeUTF8 = S
  万一
  对错误转到0
结束功能

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:

€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’""•–—˜™š›œžŸ

In that case

c=191-->c='¿'

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:我不能去code一些字符从UTF-8到ISO-8859-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆