Tinderbox v11 Icon

String.paragraphList()


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator Data Type Returned: 

Operator First Added: 

Operator in Current Baseline: 

Operator Altered Since Baseline: 

 Property  [other Property type actions]

 Item  [operators of similar scope]

 Data manipulation  [other Data manipulation operators]

 List [about List data type]

 v9.0.0

 Baseline

 As at baseline


Syntax note: Operators without any defined mandatory arguments may omit their empty closing parentheses


String.paragraphList()

String.paragraphList

The .paragraphList operator returns a list of paragraphs contained in a string. This operator requires running on macOS 10.14 and later. For example, to get a list of the discrete paragraphs in $Text:

$MyList = $Text.paragraphList; 

To set a string to the third paragraph of $Text (recall the .at(N) operator is zero-based):

$MyString = $Text.paragraphList.at(2); 

If wanting to iterate and test paragraphs, rather than chain $Text.paragraphList.each(){}, use the newer stream parsing method $Text.eachLine(){}. In both instances a line—or paragraph—is a substring—delimited by one of more successive line breaks.

Getting a random paragraph

To set a string to a random paragraph of $Text:

$MyString = $Text.paragraphList.randomItem; 

The latter uses list.randomItem and avoids using rand() and further manipulation of the returned number.

Source paragraphs containing semicolons

As .paragraphList returns a List, if any source paragraph containing a semicolon it will create more than one item in the returned list. In such circumstances, in may be better to use .eachLine() instead. Or, if encountered, a technique is to first sanitise the source by changing semicolons to another string and then back:

    var:string vSource = $Text.replace(";","@@@");
    $MyList = vSource.paragraphList;
    $MyString = $MyList.at(4)replace("@@@",";");

See also—notes linking to here: