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 / ADvanced string read/write data in external text file.

Author
Message
Kangaroo2 BETA2
22
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Somerset / UK
Posted: 28th Aug 2003 13:40
Ok so once a text file is loaded as file 1, the command "write string 1, "hello"" will add "hello" to the next free line. Also the command "read string 1, file$" will read line one of the text file. To read line 2 you call the same command again, for line three a third time, etc.

But is it possible (for example) to open a 100 line text file and read line 47 without first reading and disregarding the first 46?

And (even worse) is it possible to replace line 52 without first having to read every other line and save them as separate strings in an array, then delete the text file and make a whole new one using those strings and replacing the changed line? ( Hmm over complicating things or what!)

It would seem common sense that this is possible but I can find no such commands in the help documentation and this exceedingly long winded way seems the only (fairly limited and certainly slow) option.

If it IS possible within DBPro, how? And why isn't it documented?

If not, then has anybody made a dll or plugin to do it? Otherwise I'm stuck with my slow and confusing functions

Thanks for any feedback Sorry if this has been asked before, I don't recall discussing or reading about it, but it seems quite a normal request so it may be sorted already. I know for example that some new patches have brought new commands, which aren't always updated in help

Quikly Studio Pro. Soon. Honest.
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 28th Aug 2003 14:17 Edited at: 28th Aug 2003 14:18
I've been thinking of doing a plug-in for proper reading/writing with random access - the only thing stopping me was would it be used, and the fact that CreateFile/ReadFile/WriteFile can be a real pain to use...

You wouldn't be able to specify a line number (but you would be able to specify the byte position - a 64bit number too!). Looking for a particular line is a real pain (as you have to read in text up until the CR/LF code - either of which can be present or not present, or it could be a different code altogether.)

If you want line access, it might be worth using INI files - then the layout would be something like :

[DATA]
Line01=text
Line02=text

etc


Kangaroo2 BETA2
22
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Somerset / UK
Posted: 28th Aug 2003 17:52
Yes good idea Thank you

It seems strange that this wasn't added as standard, as you say it can get quite a pain to use

Your plug-in idea sounds great Maybe something to do if you get some spare time

Quikly Studio Pro. Soon. Honest.
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 28th Aug 2003 19:13
for opening couldn't you pad the strings out so every string is a cetain lenght.
Then for loading use skip bytes to jump to where the string you want to read is.

For writing could you copy the input file read a string from the input file copy and write is straight to the output file until you get to the string you want to change then just write the change insted of the read string. Not any better that the array method but saves you having to make a potentially big array.
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 28th Aug 2003 21:39
Yes, I might think about it at some point in the future...


Kangaroo2 BETA2
22
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Somerset / UK
Posted: 28th Aug 2003 23:31
Winch - Yes, thank you, I had thought about that. As you said, it would save large arrays in certain circumastance

Quikly Studio Pro. Soon. Honest.

Login to post a reply

Server time is: 2026-07-25 09:40:40
Your offset time is: 2026-07-25 09:40:40