A few alternatives:
Removing the last terminating characters afterwards:
open to write 1, "File.txt"
write string 1, "a"
write string 1, "b"
close file 1
RemoveLastChars("File.txt", 2) : `Remove carriage return and linefeed character from file
wait key
end
function RemoveLastChars(file$, nr)
`Find a free memblock
mem1 = 1
while memblock exist(mem1) = 1
inc mem1
endwhile
open to read 1, file$
make memblock from file mem1, 1
close file 1
`Find a new free memblock
mem2 = mem1 + 1
while memblock exist(mem2) = 1
inc mem2
endwhile
make memblock mem2, get memblock size(mem1) - nr
copy memblock mem1, mem2, 0, 0, get memblock size(mem2)
delete memblock mem1
`Write to file
if file exist(file$) then delete file file$
open to write 1, file$
make file from memblock 1, mem2
close file 1
`Delete memblock
delete memblock mem2
endfunction
Using your own customized write/read commands:
`Write
if file exist("File.txt") then delete file "File.txt"
open to write 1, "File.txt"
WriteOwnString(1, "I am text number 1", chr$(13) + chr$(10))
WriteOwnString(1, "Text number 2", chr$(13) + chr$(10)) : `Carriage return and line feed is what DBP uses
WriteOwnString(1, "I'm third!", "|") : `Some own termination character
WriteOwnString(1, "I'm fourth!", "|")
close file 1
`Read
open to read 1, "File.txt"
print ReadOwnString(1, chr$(13) + chr$(10))
print ReadOwnString(1, chr$(13) + chr$(10))
print ReadOwnString(1, "|")
print ReadOwnString(1, "|")
close file 1
wait key
end
function WriteOwnString(file, txt$, termination_characters$)
`write bytes to file
for i = 1 to len(txt$)
write byte file, asc(mid$(txt$, i))
next i
`Write termination character
for i = 1 to len(termination_characters$)
write byte file, asc(mid$(termination_characters$, i))
next i
endfunction
`Does not work when termination characters are repeated!
function ReadOwnString(file, termination_characters$)
`Keep reading bytes, until the termination character is found or end of file is reached
txt$ = ""
termination_count = 1
repeat
`Get character
read byte file, a
char$ = chr$(a)
txt$ = txt$ + char$
`Test character with termination
if char$ = mid$(termination_characters$, termination_count)
if termination_count = len(termination_characters$) then Found = 1
inc termination_count
else
termination_count = 1
endif
until Found = 1 or file end(1)
`Remove the termination characters from the string
txt$ = left$(txt$, len(txt$) - len(termination_characters$))
endfunction txt$
Though it might not be as fast as a plug-in...
[EDIT] Seems you figured it out. I guess I'll leave these snippets for future reference then.
Cheers!
Sven B