Ver Mensaje Individual
  #17 (permalink)  
Antiguo 17/10/2011, 10:29
PabloManuel
 
Fecha de Ingreso: diciembre-2010
Mensajes: 236
Antigüedad: 13 años, 5 meses
Puntos: 6
Respuesta: ASP XHTML Access y las dichosas tildes.

Bueno, pues he encontrado una solución que creo que es momentánea:

Código ASP:
Ver original
  1. <%
  2. option explicit
  3.  
  4. ' Simple functions to convert the first 256 characters
  5. ' of the Windows character set from and to UTF-8.
  6.  
  7. ' Written by Hans Kalle for Fisz
  8. ' http://www.fisz.nl
  9.  
  10. 'IsValidUTF8
  11. '  Tells if the string is valid UTF-8 encoded
  12. 'Returns:
  13. '  true (valid UTF-8)
  14. '  false (invalid UTF-8 or not UTF-8 encoded string)
  15. function IsValidUTF8(s)
  16.   dim i
  17.   dim c
  18.   dim n
  19.  
  20.   IsValidUTF8 = false
  21.   i = 1
  22.   do while i <= len(s)
  23.     c = asc(mid(s,i,1))
  24.     if c and &H80 then
  25.       n = 1
  26.       do while i + n < len(s)
  27.         if (asc(mid(s,i+n,1)) and &HC0) <> &H80 then
  28.           exit do
  29.         end if
  30.         n = n + 1
  31.       loop
  32.       select case n
  33.       case 1
  34.         exit function
  35.       case 2
  36.         if (c and &HE0) <> &HC0 then
  37.           exit function
  38.         end if
  39.       case 3
  40.         if (c and &HF0) <> &HE0 then
  41.           exit function
  42.         end if
  43.       case 4
  44.         if (c and &HF8) <> &HF0 then
  45.           exit function
  46.         end if
  47.       case else
  48.         exit function
  49.       end select
  50.       i = i + n
  51.     else
  52.       i = i + 1
  53.     end if
  54.   loop
  55.   IsValidUTF8 = true
  56. end function
  57.  
  58. 'DecodeUTF8
  59. '  Decodes a UTF-8 string to the Windows character set
  60. '  Non-convertable characters are replace by an upside
  61. '  down question mark.
  62. 'Returns:
  63. '  A Windows string
  64. function DecodeUTF8(s)
  65.   dim i
  66.   dim c
  67.   dim n
  68.  
  69.   i = 1
  70.   do while i <= len(s)
  71.     c = asc(mid(s,i,1))
  72.     if c and &H80 then
  73.       n = 1
  74.       do while i + n < len(s)
  75.         if (asc(mid(s,i+n,1)) and &HC0) <> &H80 then
  76.           exit do
  77.         end if
  78.         n = n + 1
  79.       loop
  80.       if n = 2 and ((c and &HE0) = &HC0) then
  81.         c = asc(mid(s,i+1,1)) + &H40 * (c and &H01)
  82.       else
  83.         c = 191
  84.       end if
  85.       s = left(s,i-1) + chr(c) + mid(s,i+n)
  86.     end if
  87.     i = i + 1
  88.   loop
  89.   DecodeUTF8 = s
  90. end function
  91.  
  92. 'EncodeUTF8
  93. '  Encodes a Windows string in UTF-8
  94. 'Returns:
  95. '  A UTF-8 encoded string
  96. function EncodeUTF8(s)
  97.   dim i
  98.   dim c
  99.  
  100.   i = 1
  101.   do while i <= len(s)
  102.     c = asc(mid(s,i,1))
  103.     if c >= &H80 then
  104.       s = left(s,i-1) + chr(&HC2 + ((c and &H40) / &H40)) + chr(c and &HBF) + mid(s,i+1)
  105.       i = i + 1
  106.     end if
  107.     i = i + 1
  108.   loop
  109.   EncodeUTF8 = s
  110. end function
  111. %>

Se trata de dos funciones para codificar y codificar cadenas.

Ahora los campos que me salen mal tengo que pasarlos por estas funciones, lo cual es una putada porque tendré que revisar todo el código y algo se me escapará.

Dejo pendiente las altas en la base de datos, lo cual no quiero ni pensarlo.

url original:
http://www.codetoad.com/asp_utf8.asp