Link | lp_string_wordwrap |
Author | Bil Corry |
Category | String |
Version | 8.x |
License | Public Domain |
Posted | 03 Dec 2005 |
Updated | 21 Jan 2006 |
More by this author... |
Word-wraps a string at a given line length.
Note: Requires [lp_string_firstwords], [lp_string_linefeedGet] and [lp_string_linefeedSet]
var:'length' = 5; ''; '+' * $length; '\r\n'; (lp_string_wordwrap: 'This is a test. It\'s only a test.', $length, '\r\n'); '\r\n'; '+' * $length; '\r\n'; ''; Returns: +++++ This is a test. It's only a test. +++++
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
[ define_tag:'lp_string_wordwrap', -description='Word-wraps a string at a given line length.', -priority='replace', -required='string', -copy, -required='linelength', -optional='linefeed'; #string = string: #string; if: !(local_defined:'linefeed'); local:'linefeed' = (lp_string_linefeedGet: #string); if: #linefeed == ''; #linefeed = '\r\n'; /if; else; #linefeed = string: #linefeed; /if; if: params->(find:'-striplf')->size > 0; // strip out the linefeeds #string = (lp_string_linefeedSet: #string, ' '); /if; if: #linefeed == 'array'; local:'return' = array; local:'temp' = string; local:'notrunaway' = 1000; while: #string->size && #notrunaway; #notrunaway -= 1; #temp = (lp_string_firstwords: #string, (integer:#linelength)); #string->(removeleading: #temp); #temp->trim; if: #temp->size; #return->(insert: #temp); /if; /while; else; local:'return' = string; local:'temp' = string; local:'notrunaway' = 100000; while: #string->size && #notrunaway; #notrunaway -= 1; #temp = (lp_string_firstwords: #string, (integer:#linelength)); #string->(removeleading: #temp); #temp->trim; if: #temp->size; #return += #temp #linefeed; /if; /while; #return->trim; /if; return: #return; /define_tag; ]
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft