Lasso Soft Inc. > Home

[ string->forEachLineBreak ]

Method

This method takes a capture block and executes that block once for every substring that would be generated by splitting the base string object on a line break. Every linebreak is recognized: "\r", "\n", and "\r\n". Each of the substrings can be accessed in the capture block through the special local variable "#1".

  • Syntax
'String Value'->forEachLineBreak => {
	doSomethingWithLine(#1)
}
Examples
  • Beginner

Access Each Line in a String

The following example takes a string with multiple lines and runs the lines of the string together with slashes, storing the result in the variable "quoted_poem". It removes the trailing slash at the end and then displays the variable "quoted_poem" in quotes.

Code

local(poem) = 'Our two souls therefore, which are one,\rThough I must go, endure not yet\r\nA breach, but an expansion,\nLike gold to airy thinness beat.'

local(quoted_poem) = ''

#poem->forEachLineBreak => {
    #quoted_poem->append(#1 + '/')
}
#quoted_poem->removeTrailing('/')
'"' + #quoted_poem + '"'

Result

"Our two souls therefore, which are one,/Though I must go, endure not yet/A breach, but an expansion,/Like gold to airy thinness beat."

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft