Core Function FileReadLine

From Sputnik Wiki
Jump to: navigation, search
FileReadLine( <file>, <expression> )

Contents

Description

Read a line of text from a previously opened text file (Or specify a name of a file).

Parameters

file

A variable containing the File handle OR a name of a file to open.

expression

Optional; Line number to read default is line 0 (0 means the first line).

Return Value

Success: Returns a string

Failure: Returns null if error occurs.

Remarks

Trailing newlines "\n" and "\r" will be removed from the end of the returned string automatically.

Example

$File = FileOpen("MyFile.txt", "r");
If(isVarObj($File, "file"))
{
	$Line0 = FileReadLine($File, 0);
	$Line1 = FileReadLine($File, 1);
	$Line2 = FileReadLine($File, 2);
	println( "Line0: " . $Line0 );
	println( "Line1: " . $Line1 );
	println( "Line2: " . $Line2 );
	FileClose( $File );
}

Heres an example of using it directly with a text file by name :

$Line0 = FileReadLine("MyFile.txt", 0);
$Line1 = FileReadLine("MyFile.txt", 1);
$Line2 = FileReadLine("MyFile.txt", 2);
println( "Line0: " . $Line0 );
println( "Line1: " . $Line1 );
println( "Line2: " . $Line2 );
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox