Tinderbox v9 Icon

String.eachLine(loopVar[:condition]){actions}


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Last Altered: 

Operator Has Optional Arguments: 

Operator Has Conditional Arguments: 

Operator Uses Loop Variable Argument: 


String.eachLine(loopVar[:condition]){ action(s) }

The .eachLine() operator, iterates through each line of a steam, where a line is one or more characters ending in a carriage return, line feed, unicode paragraph separator, or the end of the string (so in $Text, it means discrete paragraphs).

Each line, in turn, is bound to a temporary variable loopVar, and the action is then performed. The name of the variable is set by the user when writing the code, i.e. it is whatever string is entered where loopVar is shown above. Something like 'aLine' might be a more useful variable name.

If the optional condition is specified, only lines that satisfy the condition are processed using the action.

For example:

$MyNumber=0;
$Text.eachLine(aLine){
   $MyNumber=$MyNumber+1;
};

will set $MyNumber to the number of lines (paragraphs!) in the $Text of this note.

$MyNumber=0;
$Text.eachLine(aLine:aLine.contains("@")){
   $MyNumber=$MyNumber+1;
};

will set $MyNumber to the number of lines in the $Text that contain the "@" symbol.

When parsing text paragraphs, this operator can substitute for the older method of chaining .paragraphList.each(){}.

From v9.6.0, .eachLine(){} no longer skips whitespace at the start of the line.