reading/displaying UTF-8 TXT file

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

reading/displaying UTF-8 TXT file

Post by serge_girard »

Hello,

I need to upload some data from a text-file (saved as UTF-8) containing: ë, ç, à, á, â,ã,ä,å,æ,ç,è.. etc...
Reading this file and displaying the content in another file is no problem, but displaying on screen gives
something like this: Préporché instead of Préporché.

So my input file contains "Préporché", writing to new file is OK but displaying on the screen is not.
How to fix this problem?

Serge
There's nothing you can do that can't be done...
SvargasD
Posts: 12
Joined: Sat Mar 24, 2018 2:50 pm
DBs Used: DBF

Re: reading/displaying UTF-8 TXT file

Post by SvargasD »

Hola Serge:

Hace tiempo tuve el problema al revés, mi archivo de texto generaba caracteres extraños al guardar. Lo solucione con ayuda de este foro donde recurrí al juego de caracteres que puedes configurar en cada programa que generas.

REQUEST HB_CODEPAGE_ESWIN
HB_SETCODEPAGE("ESWIN")
REQUEST HB_LANG_ES
HB_LANGSELECT( "ES" )
SET LANGUAGE TO SPANISH

Por el error que mencionas, me parece que el problema esta con la configuración de idiomas del sistema operativo que ejecutas, talvez si revisas la configuración regional y de idiomas de Windows podrías solucionarlo.
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: reading/displaying UTF-8 TXT file

Post by serge_girard »

Hi SvargasD,

Thanks, but it doesn't work....

Serge
There's nothing you can do that can't be done...
jparada
Posts: 433
Joined: Fri Jan 23, 2009 5:18 pm

Re: reading/displaying UTF-8 TXT file

Post by jparada »

Hi,
I have just that drawback and it actually has to do with the OS codepage and even the codepage of the editor with which you write your code.

When the problem is just as you mentioned about displaying on the screen, I personally solve it with hb_Utf8ToStr, since my code editor is set to UTF-8 and my Windows codepage is different.

Hope it helps you.

Regards,
Javier
User avatar
serge_girard
Posts: 3309
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: reading/displaying UTF-8 TXT file

Post by serge_girard »

Javier,

Thanks this has brought me to the solution:

Code: Select all


REQUEST HB_CODEPAGE_FRWIN
hb_setcodepage("FRWIN")


//then:

IF hb_StrIsUTF8(cSTR)
   cSTR      := hb_utf8tostr(cSTR, 'FRWIN')
ENDIF
// this is the correct translation !!

Thanks again !


Serge
There's nothing you can do that can't be done...
Post Reply