Operator Type:
Operator Scope of Action:
Operator Purpose:
Operator First Added:
Operator Altered:
Function [other Function type actions]
Item [operators of similar scope]
Stream parsing [other Stream parsing operators]
9.1.0
Stream.try{ action(s) }[.thenTry{ action(s) }]
If the first test action fails, they restore the string and allow you to process it a different way. The current success/failure state can be tested using the failed() operator.
Saves the value of an attribute (the steam source) and attempts an action. If the action fails because one of its operators fails or the fail() operator is performed, the original value of stream source is restored.
A .try{} may be followed by one or more .thenTry{} clauses. If the original .try{} succeeds, all subsequent .thenTry{} clauses are ignored. If the original .try{} fails, then each .thenTry{} is attempted in turn. Once a .thenTry{} clause succeeds, subsequent .thenTry{} clauses are ignored.
For example:
$MyString.try{
$MyString=$MyString.skipToWord("To:").captureWord;
}
looks for strings such as "To:John Doe"
If the string "To:" is not found, $MyString will be unchanged. If found, $MyString is replaced by the word that follows, up to the next whitespace character or the end of the string, i.e. "John".