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 Discussion / .txt and string manipulation

Author
Message
Plugged
22
Years of Service
User Offline
Joined: 30th Nov 2002
Location: Hertfordshire
Posted: 25th Jan 2006 11:45
hi guys i was wonder if any one could help me. I need to write a function to load a .txt file and put a specific line in to a string. so the basics would be

function loadline(linenumber)
open to read "text.txt",1
`read the line this is the bit i need help with
close file 1
endfunction line$

could you possibly load all the characters into an array and the do something like

line$=""
x=0
repeat
line$=line$+array$(x)
inc x
until array$(x)=whatever the code for return is.

anyway a point in the right direction would be never nice.

cheers
Plugged


Work Hard; Play Harder ;
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 25th Jan 2006 12:35 Edited at: 25th Jan 2006 12:51
read string (File Number),(Variable to store the string)

array$=""
x=1
repeat
if x < len(line$) then array$=array$+mid$(line$,x) else exit
inc x
until array$=(whatever the code for return is.)

like that?

Or perhaps...

repeat
if file end(1) = 0 then read string 1,line$ else exit
until line$=whatever the code for return is.
close file 1

First example adds one more character to the end of the line each time until there are no more characters to add, while the second one reads the next line in the file (so long as there is another line to read...)

...maybe one day I'll finish a project

Login to post a reply

Server time is: 2025-05-23 02:27:45
Your offset time is: 2025-05-23 02:27:45