FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to read a unicode TXT file
Posts: 300
Joined: Wed Jul 11, 2007 11:06 AM
How to read a unicode TXT file
Posted: Thu Mar 02, 2017 08:15 PM

Hi,
What is the instruction to open a Unicode TXT file .

Thanks for your help .

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to read a unicode TXT file
Posted: Fri Mar 03, 2017 01:47 AM
MemoRead() or any other file read function of (x)Harbour can read Unicode (utf-8) text file.

For display and edit Unicode text set FW_SetUnicode( .T. ). MemoEdit() and GET MEMO can edit and save Unicode text.

Code (fw): Select all Collapse
   local cUnicodeText

   FW_SetUnicode( .t. )

   cUnicodeText   := MEMOREAD( "unicode.txt" )

   MEMOEDIT( cUnicodeText )
Regards



G. N. Rao.

Hyderabad, India
Posts: 1956
Joined: Fri Oct 07, 2005 07:08 PM
Re: How to read a unicode TXT file
Posted: Thu Sep 30, 2021 03:13 PM
Buen dia.
este codigo al ejecutarlo no me visualiza bien las lineas. no me aparecen las ñ

Code (fw): Select all Collapse
  hF := ttxtFile():new( cFilePath( exename() ) + "doc\1.txt" )
   FW_SetUnicode( .T. )
   hf := MemoRead( cFilePath( exename() ) + "doc\1.txt"  )
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to read a unicode TXT file
Posted: Thu Sep 30, 2021 03:35 PM

1.txt may not be containing UTF8 text.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1956
Joined: Fri Oct 07, 2005 07:08 PM
Re: How to read a unicode TXT file
Posted: Thu Sep 30, 2021 09:35 PM
me pasa que esta linea me la transforma en 2 lineas:
Code (fw): Select all Collapse
Shampoo Anti Age con Acido Hialuronico Cab. Dañados por el paso del tiempo 1 Lt C/valv

hasta cuando lo muestro en un xbrowse
Code (fw): Select all Collapse
 hf := memoread( cFilePath( exename() ) + "doc\1.txt" )

   FOR x = 1 TO MLCount( hf )
      cLinea:= MemoLine( hf,,x,.t.)
      AAdd(a, cLinea)
   NEXT

   XBROWSER a
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to read a unicode TXT file
Posted: Fri Oct 01, 2021 01:11 AM
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oDlg, oFont, oBrw, cText

   cText := "Shampoo Anti Age con Acido Hialuronico Cab. Dañados por el paso del tiempo 1 Lt C/valv"

   ? cText

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-20
   DEFINE DIALOG oDlg SIZE 560,200 PIXEL TRUEPIXEL FONT oFont

   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE { cText } ;
      COLUMNS 1 HEADERS "TEXT" COLSIZES 500 ;
      LINES NOBORDER

   WITH OBJECT oBrw
      :nRowHeight    := 60
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil




Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to read a unicode TXT file
Posted: Fri Oct 01, 2021 02:39 PM
goosfancito wrote:me pasa que esta linea me la transforma en 2 lineas:
Code (fw): Select all Collapse
Shampoo Anti Age con Acido Hialuronico Cab. Dañados por el paso del tiempo 1 Lt C/valv

hasta cuando lo muestro en un xbrowse
Code (fw): Select all Collapse
 hf := memoread( cFilePath( exename() ) + "doc\1.txt" )

   FOR x = 1 TO MLCount( hf )
      cLinea:= MemoLine( hf,,x,.t.)
      AAdd(a, cLinea)
   NEXT

   XBROWSER a


Look at the second parameter of MLCount() and MemoLine. Set a proper value.

EMG

Continue the discussion