Page Blocks

Hosting sponsored by:

Point In Space

 

API: Str

Filename:
fwpStr_getWords.ctag

Released With:
5.0.0

Current Version:
1.0.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwpStr_getWords (Tag)

Description

Retrieves N words (characters deliemited by spaces) froma specified string.

Syntax

[fwpStr_getWords: -str=string, -get=integer]

Parameters & Member Tags

-str - required : a string

-get - required : the number of words to retrieve

Examples

[fwpStr_getWords: -str=field:'description', -get='50']

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpStr_getWords.ctag }
    {rsrcType=        tag }
    {rsrcName=        fwpStr_getWords }
    {rsrcHTTP=        www.pageblocks.org/refc/fwpStr_getWords }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            This tag returns 'max' chars of string 'str' with an
                    intelligent cutoff at whole words. }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release - replaces fwpUtil_subWords }

*/
//.............................................................................

define_tag:'fwpStr_getWords', -priority='replace',
    -required='str',
    -required='get';

    local:
        'fw_get'         = #get,
        'fw_allPieces'    = #str->(split:' '),
        'fw_rtnPieces'    = (array);

    if: #fw_get > #fw_allPieces->size;
        #fw_get = #fw_allPieces->size;
    /if;

    loop: #fw_get;
        #fw_rtnPieces->(insert:#fw_allPieces->(get:loop_count));
        #fw_rtnPieces->(insert:' ');
    /loop;
    #fw_rtnPieces = #fw_rtnPieces->join;
    #fw_rtnPieces->(removetrailing:' ');

    return: #fw_rtnPieces;

/define_tag;
?>

© 2002-2010, pageblocks.org