Text File (SOLVED)

Text File (SOLVED)

Postby Jeff Barnes » Tue May 30, 2017 11:57 pm

I have a text file the when opened with Notepad, all the data is strung together.
If I open the same file with UltraEdit it asks me "Do you want to convert test.asc to DOS format"
When I answer "yes" the data is separated into individual lines. This is what I am looking to get via code.

Does anyone know how I can do this conversion?
I want to be able to grab data via MemoLine() to get to the data I need.

Here is a sample of the text file (.asc) if anyone needs to see what I'm tallking about;
http://www.can-soft.net/dlnew/test.asc
Last edited by Jeff Barnes on Wed May 31, 2017 12:16 pm, edited 1 time in total.
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Text File

Postby Massimo Linossi » Wed May 31, 2017 6:58 am

In this file the end of line is a chr(10) and not a chr(13) + chr(10).
You can read it in this way.

Code: Select all  Expand view
filename = "test.asc"

handle = fopen(filename)
stringa = space(500)
fread(handle, @stringa, 200)
if chr(13) + chr(10) $ stringa
    end_of_line = chr(13) + chr(10)
else
    if chr(13) $ stringa
        end_of_line = chr(13)
    else
        end_of_line = chr(10)
   endif
endif
fclose(handle)

handle = fopen(filename)
do while .t.
      stringa = space(500)
      if hb_freadline(handle, @stringa, { end_of_line },500 ) < 0
          exit
      endif

      //process stringa here

enddo
fclose(handle)
User avatar
Massimo Linossi
 
Posts: 498
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: Text File

Postby nageswaragunupudi » Wed May 31, 2017 10:25 am

Code: Select all  Expand view

cText := memoread( cfile )
cText := StrTran( StrTran( cText, CRLF, Chr(10) ), Chr(10), CRLF )
MEMOWRIT( cFile, cText
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Text File (SOLVED)

Postby Jeff Barnes » Wed May 31, 2017 12:15 pm

Thank you. Works perfectly now :)
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Silvio.Falconi and 44 guests