FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Utf8toAnsi() with italian accented characters
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Utf8toAnsi() with italian accented characters
Posted: Tue Jun 24, 2025 10:32 AM

I have a text file in utf8 mode that encodes the Italian accented characters (àèéìòù and some others) with 2 bytes.

with notepad I save this text in another file in Ansi mode and the accented characters are encoded with 1 byte.

And all works fine.

shouldn't the function Utf8toAnsi() of fivewin do the same thing?

and yet I don't get the same result. is there perhaps some other more appropriate function?

thanks in advance, Marzio

Posts: 129
Joined: Mon Oct 17, 2005 03:03 AM
Re: Utf8toAnsi() with italian accented characters
Posted: Tue Jun 24, 2025 11:57 PM

use: hb_strToUTF8(<cStr>,[<cCPID>]) ➔ <cUTF8Str>

line ID: ssbbstw

WeChat ID: ssbbstw
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Utf8toAnsi() with italian accented characters
Posted: Wed Jun 25, 2025 07:13 AM

thanks for your reply,

but this function doesn't resolve the problem.

i have to obtain the contrary, that is: hb_Utf8toStr() but this function is the same Utf8toAnsi()

Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM
Re: Utf8toAnsi() with italian accented characters
Posted: Wed Jun 25, 2025 10:22 AM
Hi Marzio,

try this
....
HB_SetCodePage( "ITWIN" )
cBuf := HB_UTF8TOSTR( cBuf )
HB_SETCODEPAGE()
....
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Utf8toAnsi() with italian accented characters
Posted: Wed Jun 25, 2025 01:19 PM
MaxP wrote: Hi Marzio,

try this
....
HB_SetCodePage( "ITWIN" )
cBuf := HB_UTF8TOSTR( cBuf )
HB_SETCODEPAGE()
....
many thanks MaxP,

i have had tried theese CODEPAGE italia: 20280 (IBM EBCDIC Italy) e 1144 (IBM EBCDIC Italia IBM EBCDIC (Italy-Euro))
but theese do not work.

HB_SetCodePage( "ITWIN" ) works fine. this resolve my problem!
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Utf8toAnsi() with italian accented characters
Posted: Wed Jun 25, 2025 04:42 PM
Have you tried with CP1252 ??
HB_CDPSELECT( "UTF8" )

HB_StrToUTF8()
Núcleo Harbour (instalado):
hb_cdpIsUTF8()
hb_StrIsUTF8()
hb_StrToUTF8()
hb_utf8Asc()
hb_utf8At()
hb_utf8Chr()
hb_utf8Left()
hb_utf8Len()
hb_utf8Peek()
hb_utf8Poke()
hb_utf8RAt()
hb_utf8Right()
hb_utf8StrTran()
hb_utf8Stuff()
hb_utf8SubStr()
hb_UTF8ToStr()
hb_UTF8ToStrBox()
HB_CODEPAGE_UTF16LE()
HB_CODEPAGE_UTF8()
HB_CODEPAGE_UTF8EX()
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Utf8toAnsi() with italian accented characters
Posted: Thu Jun 26, 2025 07:51 AM
karinha wrote: Have you tried with CP1252 ??
many thanks also to you Karinha,

"CP1252" and "ITWIN" works fine.

many useful also the list of the UTF8 functions.
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Utf8toAnsi() with italian accented characters
Posted: Thu Jun 26, 2025 01:07 PM

Thanks for the feedback. It would be super important if you could post a simple example so that other users can get informed in the future. Is that possible?

Gracias por tus comentarios. Sería fundamental que publicaras un ejemplo sencillo para que otros usuarios puedan informarse en el futuro. ¿Es posible?

Gracias, tks.

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 193
Joined: Wed Apr 04, 2007 06:54 AM
Re: Utf8toAnsi() with italian accented characters
Posted: Thu Jun 26, 2025 02:15 PM
ctext := "buongiorno, ìàéèùò"   // italian accented characters

HB_SetCodePage( "UTF8" )      // or HB_SetCodePage( "EN" )
? UTF8toAnsi(cText)               // "buongiorno, …‚Š—•"

HB_SetCodePage( "ITWIN" )     // or HB_SetCodePage( "CP1252" )
? UTF8toAnsi(cText) 		 // "buongiorno, ìàéèùò"
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Utf8toAnsi() with italian accented characters
Posted: Thu Jun 26, 2025 03:12 PM
Very good, tks for the feedback.
// C:\FWH\SAMPLES\ITALIAPG.PRG

#include "FiveWin.ch"

EXTERNAL HB_LANG_IT, HB_CODEPAGE_PTISO, HB_CODEPAGE_ITWIN

#ifNdef __XHARBOUR__     // Only HARBOUR
   REQUEST HB_CODEPAGE_UTF8
   REQUEST HB_CODEPAGE_UTF8EX
#endif

FUNCTION Main()

   LOCAL cText

   #ifdef __XHARBOUR__  // PERFEITO COM XHARBOUR( I Like )

      HB_LANGSELECT( 'IT' )     // Default language is now Italiann
      HB_SETCODEPAGE( "ITWIN" ) // or HB_SetCodePage( "CP1252" )
      HB_CDPSELECT( "PTISO" )
      HB_SETCODEPAGE( "UTF8" )

   #Else // HARBOUR:

      HB_LANGSELECT( 'IT' )
      HB_SETCODEPAGE( "UTF8" )
      HB_CDPSELECT( "UTF8EX" )
      HB_SETCODEPAGE( "ITWIN" )   // or HB_SetCodePage( "CP1252" )
      HB_CDPSELECT( "PTISO" )

   #Endif

   cText := "buongiorno, ìàéèùò"  // italian accented characters

   // HB_SetCodePage( "UTF8" )    // or HB_SetCodePage( "EN" )

   ? UTF8toAnsi( cText )          // "buongiorno, …‚Š—•"

   // HB_SetCodePage( "ITWIN" )   // or HB_SetCodePage( "CP1252" )

   ? UTF8toAnsi( cText )          // "buongiorno, ìàéèùò"

RETURN NIL

// FIN / END                kapiabafwh@gmail.com
Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion