Text File (SOLVED)

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Text File (SOLVED)

Post by Jeff Barnes »

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 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Massimo Linossi
Posts: 474
Joined: Mon Oct 17, 2005 10:38 am
Location: Italy

Re: Text File

Post by Massimo Linossi »

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

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
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Text File

Post by nageswaragunupudi »

Code: Select all

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

G. N. Rao.
Hyderabad, India
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Re: Text File (SOLVED)

Post by Jeff Barnes »

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

(FWH 12.01, xHarbour 1.2.1, Bcc582)
Post Reply