Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FGETS() to know if linefeed
Message
From
09/08/2002 05:53:14
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00687804
Message ID:
00687866
Views:
10
>Hi All,
>I have a text file that I open and read data from. The problem is that its format is not in a form of a dellimited text file. Its kind of a report that is exported to a text file. Though this is the case, I have found that fields are in a fixed-width. So , I try to FGETS() each line, get the string data from it, count the fixed-width characters I need and do some processing. But some lines, FGETS() returns empty twice or thrice (but if text file is opened in say notepad.exe, actual line only has spaces in them). Could it be that those "spaces" are linefeeds or carriage returns? But when I try to see if they are, FREAD() returns CHR(32). I need to just scan all the lines in a text file, from the return value get n characters from it. Each "detail record" I know for sure is x lines, but between each "detail record" I dont know how many "spaces"/linefeeds/carriage returns. Any help would do, thanks!

Charles,
For fgets() (and other functions checking EOL) end of a line is a CRLF (ASCII 13+10), LF or CR. ie:

'line1'+chr(13)+chr(13)+chr(10)+chr(13)+chr(10)+chr(10)+'this is line5'

Note chr(13)+chr(10) pair -CRLF- (and in that order) is accepted as a one 'newline' character. If it's chr(10)+chr(13) than it's 2 'newlines'.

You say the fields are in a fixed-width :) Sounds like your text file is a perfect candidate for 'append from'. If you use 'append from' you have the liberty of working backward-forward more easily, eliminating 'empty' lines in first place, converting types on the fly etc and compared to fgets() it might even prove to be faster in your case. ie: you decided it'd constitute 5 columns with first 4 are 10 in width char, last one is a numeric value (say an integer) and more integer value should never be lte 0 :

create cursor myCursor (f1 c(10), f2 c(10), f3 c(10), f4 c(10), f5 i)
append from myText.txt type SDF for f5 > 0

Simple and easy it'd be. Actually many text files fit into one form or another of 'append from'. Just .02 cents.

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform