FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Save csv file in utf8 with BOM
Posts: 244
Joined: Mon Jun 05, 2006 09:39 PM

Save csv file in utf8 with BOM

Posted: Wed Sep 06, 2023 07:32 PM
The characters are in the utf8 standard, but when I import it into a third-party system, it says that the file is not utf8.

Does anyone have a solution?
Code (fw): Select all Collapse
Method N_SignoCepLayout_BuildAll(f_cFileCvsSalva)
   Local lc_cFileCvsConteudo := ""

   ::N_SignoCepLayout_CabecalhoBuild()

   lc_cFileCvsConteudo     := ::cCabecalhoCampos + CRLF
   lc_cFileCvsConteudo     += ::cTxtOcorrenciasAll

   hb_MemoWrit(f_cFileCvsSalva,hb_StrToUTF8(lc_cFileCvsConteudo))

Return Nil
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM

Re: Save csv file in utf8 with BOM

Posted: Thu Sep 07, 2023 04:54 AM
What characters do you add in the header?
Please, try
Code (fw): Select all Collapse
.../...
   lc_cFileCvsConteudo     := ::cCabecalhoCampos //+ CRLF
   lc_cFileCvsConteudo     += hb_StrToUTF8(::cTxtOcorrenciasAll)

   hb_MemoWrit(f_cFileCvsSalva,lc_cFileCvsConteudo)
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 244
Joined: Mon Jun 05, 2006 09:39 PM

Re: Save csv file in utf8 with BOM

Posted: Thu Sep 07, 2023 11:23 AM
Hello Cristobar. I already solved it by applying the header to utf8 BOM
Code (fw): Select all Collapse
Method N_SignoCepLayout_BuildAll(f_cFileCvsSalva)
   Local lc_cFileCvsConteudo := ""
   Local lc_cUtf8Header := ""

   ::N_SignoCepLayout_CabecalhoBuild()

   lc_cFileCvsConteudo     := ::cCabecalhoCampos + CRLF
   lc_cFileCvsConteudo     += ::cTxtOcorrenciasAll

   lc_cUtf8Header := chr(239)+chr(187)+chr(191) //Header utf8 with BOM

   hb_MemoWrit(f_cFileCvsSalva,lc_cUtf8Header+hb_StrToUTF8(lc_cFileCvsConteudo))

Return Nil

Continue the discussion