Writing a file without line feed.
#1
I want to replace text strings of a binary file (a P2000T .CAS file). Unfortunately, QB64 adds a line feed character. When I use "PRINT" it adds a CHR$(13) or CHR$(10), when I use "WRITE" it put a double quote at the beginning of the file. How can I prevent this?


Code: (Select All)
[quote]
oldstring$ = "beatles"
newstring$ = "stones"
filename$ = "original.BIN"
oldlength% = Len(oldstring$)
newlength% = Len(newstring$)
f1% = FreeFile
f2% = f1% + 1
Open filename$ For Binary As f1% 'Bron
Open "replace.tmp" For Output As f2% 'Temp
While Not EOF(f1%)
    Line Input #f1%, line$
    lineptr% = 1

    Do
        foundptr% = InStr(lineptr%, line$, oldstring$)
        If foundptr% > 0 Then
            line$ = Left$(line$, foundptr% - 1) + newstring$ + Mid$(line$, foundptr% + oldlength%)
            'Vervang oude door nieuwe string
            lineptr% = foundptr% + newlength%
            If lineptr% > Len(line$) Then Exit Do
        Else Exit Do ' Oude string niet gevonden, door naar volgende regel
        End If
    Loop
    Print #f2%, line$ ' Regel toevoegen
Wend

Close f1%: Close f2%
Kill filename$ ' Wis bronbestand
Name "replace.tmp" As filename$ ' Temp wordt nu bron

[/quote]
Reply


Messages In This Thread
Writing a file without line feed. - by SquirrelMonkey - 07-08-2022, 04:46 PM
RE: Writing a file without line feed. - by bplus - 07-08-2022, 04:58 PM
RE: Writing a file without line feed. - by bplus - 07-08-2022, 05:10 PM
RE: Writing a file without line feed. - by bplus - 07-08-2022, 05:56 PM



Users browsing this thread: 5 Guest(s)