Sver
Full Member
Posts: 145
|
Post by Sver on Aug 29, 2020 2:21:09 GMT -5
Is it possible to remove a character when a file is open as binary ?
Null byte ?
'binary file example
open "letter.txt" for binary as #myfile
txt$ = "test" '4 char
print #myfile, txt$
close #myfile
|
|
|
Post by Rod on Aug 29, 2020 14:39:12 GMT -5
In a binary file you typically seek out a byte position and read or write it. You don’t just #myfile, txt$. So we need to see more of what you are trying to do.
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Aug 30, 2020 3:02:24 GMT -5
When i print "test" to a binary file, then lenght is 4 characters.
When i print "te" to this binary file, it have to be 2 characters long.
Can i delete the last 2 bytes ?
'writeline text to line 5 ( textfile )
nomainwin
regel=5 'print to line x
if regel=0 then wait 'not allowed
newword$="5"
open "letter.txt" for input as #i
f$ =input$( #i, lof( #i))
close #i
'-----------------------------------------------------
' find startpos
regel=regel-1
start=0
for i=1 to regel
start=instr(f$, chr$(13), start+1)
next
'-------------------------------------------------------
' find endpos
regel=regel+1
eind=0
for i=1 to regel
eind=instr(f$, chr$(13), eind+1)
next
'-------------------------------------------------------
'how many lines
y=0
lengte=len(f$)
for q = 1 to lengte
a$=mid$(f$,q,1)
f=asc(a$)
if f=13 then y=y+1
next
y=y+1 'lines now
'----------------------------------------------
if regel>y then goto [addnewline]
'------------------------------------------
'string upto "line x"
if regel>1 then
links$=left$(f$,start+1) 'incl enter
else
links$=left$(f$,start) 'excl enter
end if
'--------------------------------------------------
'string after "line x"
rechts$=right$(f$,lengte-(eind-1)) 'incl enter
'-----------------------------------------------
'total string
f$= links$+newword$+rechts$
'print
open "letter.txt" for output as #i
print #i, f$
close #i
'------------
'print "ready"
wait
[addnewline]
dif=regel-y
'---------
g=0
while g<dif
g=g+1
f$=f$+chr$(13)
wend
'--------------------------
f$=f$+newword$
open "letter.txt" for output as #i
print #i, f$
close #i
'------------
'print "ready"
wait
I works. but I have to open for input, close and open for output and close. In a binary file, i can read and write. I can make a database with unlimeted field.
|
|
|
Post by Rod on Aug 30, 2020 11:26:07 GMT -5
In a binary file the record pointer becomes king. So SEEK to where the two bytes are and overwrite new values.
But the concept of erasing data within a binary file is false, the file structure never changes bytes remain bytes until they are zeroed but remain in place or are overwritten with new values. But you don’t ever remove the two bytes.
So I think we have some wrong perceptions about binary files.
|
|