Blitz3D+ Command Reference

ReadLine$ ( stream )

Parameters

stream - a file stream opened for reading, or a TCP stream

Description

Reads one line of text from a file or stream.

This is the command for plain text files - config files people can edit in Notepad, dialogue scripts, CSV-ish level data. Each call returns the next line as a string, without its end-of-line characters.

A line ends at a linefeed or at the end of the file, and carriage returns are stripped out, so both Windows-style (CR LF) and Unix-style (LF) text read cleanly.

Reading past the end of the file returns "" rather than raising an error - loop with While Not Eof(file) to read a whole file of unknown length. Note an empty line also returns "", which is why Eof is the loop condition rather than the string itself.

See also: WriteLine, ReadString, ReadFile, Eof.

Example

; ReadLine Example
; ----------------

; Write a plain-text save file so there is something to read
file=WriteFile("demo_savegame.txt")
WriteLine file,"player=Robo"
WriteLine file,"score=11657"
WriteLine file,"level=7"
CloseFile file

Print "Lines read from demo_savegame.txt:"

; ReadLine$ reads one whole line of text, without its line ending
file=ReadFile("demo_savegame.txt")
While Not Eof(file)
    Print "  "+ReadLine$(file)
Wend
CloseFile file

; Clean up the demo file
DeleteFile "demo_savegame.txt"
Print "Deleted demo_savegame.txt"

Print ""
Print "Press any key to close the example"
WaitKey

End

Index