Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / File read string/skip bytes

Author
Message
Jean Philippe
19
Years of Service
User Offline
Joined: 10th Jul 2007
Location:
Posted: 21st Apr 2011 11:54
Hi,

Am using Dbpro to open files and collect data.
Am looking for a specific string before I start extracting data from the string I read.
So I have a while loop like this one

while str$<>"test"
read string 1,str$
endwhile
...

Let's say I know my trigger won't appear in the 200 first strings/lines. Does anyone know a way to skip those 200 first lines better than a for loop

for line=1 to 200
read string 1,str$
next

Am thinking something like "skip bytes"(although I haven't checked skiping was faster than reading yet). Since I don't know how many bytes each line/string contains, I can't use it.

Thanks
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Apr 2011 15:09
Not with strings, because your never sure how long the string is, but I'm sure that binary files would work out fine if you were using bytes. Like skipping 200 bytes should be easy with binary access files - but then your probably as well just loading the file into a memblock, then you can grab any part of the memblock right away - like loading the file in as 1 block, then reading the data from it before deleting. I think memblocks are the way to go, as long as your not using strings - if you need strings, then you have to use fixed width strings.

It's like an old database format, like Foxpro, DBase, .DBF files - all the strings in that need to have a fixed length otherwise the file can't be skipped. When loading, it works out the length of each record, with all the fields combined, might be 100 bytes made from a dozen different fields, but that 100 byte length doesn't change. This means the DBF files can be loaded as binary access, and skip to any record required - add in indexed record lists, and you have a fairly efficient database system. Unrestricted string fields, memo's if you like, would be stored in a seperate file and not indexed.

Anyway, I think that you need to establish the record 'footprint' first, what fields and data does each record keep, what data types. With memblocks you could mix things up with integers and floats, because they both use 4 bytes.

Health, Ammo, and bacon and eggs!
Jean Philippe
19
Years of Service
User Offline
Joined: 10th Jul 2007
Location:
Posted: 21st Apr 2011 16:10
thanks for the clarification
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 21st Apr 2011 16:48
If you're just working with strings you could put those into an array and use SAVE ARRAY/LOAD ARRAY to save/load the text file. Once it's in an array you can start the search from Tex$(199) which would be string #200.



Login to post a reply

Server time is: 2026-07-18 06:41:19
Your offset time is: 2026-07-18 06:41:19