Link | lp_string_firstwords |
Author | Bil Corry |
Category | String |
Version | 8.x |
License | Public Domain |
Posted | 03 Dec 2005 |
Updated | 19 Mar 2008 |
More by this author... |
Returns the first series of words in a string, up to a max length.
// test vector adapted from Jason Huck: http://devblog.jasonhuck.com/2007/10/02/smart-string-truncation-in-lasso/ ''; var('str' = 'The quick, brown-fox jumps over it\'s "lazy" dog.'); loop($str->size + 10); loop_count + ' - ' + lp_string_firstwords($str, loop_count) + '\n'; /loop; '';
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_firstwords', -description='Returns the first series of words in a string, up to a max length.', -priority='replace', -required='string', -required='max_length', -optional='delimiter'); // default is any non-alphanumeric character !local_defined('delimiter') ? local('delimiter' = '(?:$|\\W)+'); local('result' = string_findregexp(#string, -find='(?is)(^.{1,'+#max_length+'})'+#delimiter)); if(#result->size == 2); return(#result->get(2)); /if; return(''); // empty string when no words are found /define_tag; ]
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
Workaround for PCRE issues