Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 22-03-2010
Avatar de Softweb
Softweb Softweb is offline
Miembro
 
Registrado: ago 2008
Posts: 46
Poder: 0
Softweb Va por buen camino
UTF8 La maldicion

Hola a todos.

Tengo una aplicación ya muy currada que me tiene pillados mas de un mes con el siguiente problema.

Tengo una variable de tipo WideString que contiene un texto en formato UTF8 y tengo que pasarlo a una variable string pero con los caracteres de acentuados correctamente y no encuentro la forma de transformar los caracteres el string (ansi).

E usado sin éxito:
Utf8ToAnsi
UTF8Encode
UTF8Decode
WideCharToString
WideStringToStringEx


Rogaría me contestaran aunque solo sea para darme una pista.

Saludos
Responder Con Cita
  #2  
Antiguo 22-03-2010
Avatar de yapt
yapt yapt is offline
Miembro
 
Registrado: sep 2006
Ubicación: España
Posts: 258
Poder: 18
yapt Va por buen camino
Seguro que ya has probado esto, pero en Delphi 2010, a mí me funciona bien.
Código Delphi [-]
var
  a : AnsiString;
  s : WideString;
begin
 s := 'Avión';
 a := AnsiString(s); 
end;

De hecho también funcionaría así:

Código Delphi [-]
  s := 'Avión';
  a := s;

No sé... si tienes alguna pista más....

Saludos.
Responder Con Cita
  #3  
Antiguo 25-03-2010
Avatar de Softweb
Softweb Softweb is offline
Miembro
 
Registrado: ago 2008
Posts: 46
Poder: 0
Softweb Va por buen camino
Cita:
Empezado por yapt Ver Mensaje
Seguro que ya has probado esto, pero en Delphi 2010, a mí me funciona bien.
Código Delphi [-]var a : AnsiString; s : WideString; begin s := 'Avión'; a := AnsiString(s); end;


De hecho también funcionaría así:

Código Delphi [-] s := 'Avión'; a := s;


No sé... si tienes alguna pista más....

Saludos.
Gracias yapt por responder, ya lo e solucionado gracias a una pista sobre la función MultiByteToWideChar, e creado una función para la conversión.

Código Delphi [-]
function UTF8ToWideString(const S: AnsiString): WideString;
var
  BufSize: Integer;
begin
  Result := '';
  if Length(S) = 0 then Exit;
  BufSize := MultiByteToWideChar(CP_UTF8, 0, PAnsiChar(S), Length(S), nil, 0);
  SetLength(result, BufSize);
  MultiByteToWideChar(CP_UTF8, 0, PANsiChar(S), Length(S), PWideChar(Result), BufSize);
end;

Saludos y gracias por responder
Responder Con Cita
  #4  
Antiguo 25-03-2010
Avatar de yapt
yapt yapt is offline
Miembro
 
Registrado: sep 2006
Ubicación: España
Posts: 258
Poder: 18
yapt Va por buen camino
Ok...

me doy cuenta ahora de que no indicabas la versión de Delphi con la que estás trabajando.

El tema es que en Delphi 2009 y 2010 todo el trabajo con UTF8 ya está muy "elaborado".

Pero si son versiones anteriores, entonces es cuando tienes que usar funciones como la que describes...

Supongo que es por eso...

Saludos y suerte... :-)
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Cambiar CHARACTER SET NONE a UTF8 en FIREBIRD 1.5 ASAPLTDA Firebird e Interbase 1 06-03-2008 00:22:54
Codificar texto en UTF8 xio Internet 0 29-10-2007 18:10:19
La maldición de Vilas Delphius La Taberna 2 14-03-2007 03:39:32
La maldición del oráculo dec Debates 1 07-02-2006 07:27:38
La maldicion del 1521... Xianto Oracle 2 18-08-2005 15:26:24


La franja horaria es GMT +2. Ahora son las 21:21:14.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi