Lasso Soft Inc. > Home

[lsd_string_replacemultiple]

Linklsd_string_replacemultiple
AuthorBrad Lindsay
CategoryString
Version8.5.x
LicensePublic Domain
Posted20 Apr 2009
Updated21 Jun 2010
More by this author...

Description

This tag loops through an array of pairs using the values in the pairs to find substrings and replace them with other strings. It does not modify the string in place, but returns a new string I used an array of pairs instead of a map so that the order could be specified. This allows earlier replacements to contain text that later gets replaced Required Paramaters: -------------------- a_string should contain the string to process replacements should contain an array of pairs with - the first item in each pair should be the string to find - the second item in each pair should be the replacement string

Sample Usage

lsd_string_replacemultiple('Now is the REPLACE_ME to come to the aid AND_ME_TOO',array(pair('REPLACE_ME'='for all good men'),pair('AND_ME_TOO'='of their country')));
//This also works:
lsd_string_replacemultiple('Now is the REPLACE_ME to come to the aid AND_ME_TOO',array('REPLACE_ME'='for all good men', 'AND_ME_TOO'='of their country'));

Source Code

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('LSD_String_ReplaceMultiple', -required='a_string', -required='replacements', -priority='replace');
    // Processes a string replacing based on an array of pairs and returns the new string
    // (Note, I used an array of pairs instead of a map so that the order could be specified)
    // a_string should contain the string to process
    // replacements should contain an array of pairs with 
    //    - the first item in each pair should be the string to find
    //    - the second item in each pair should be the replacement string
    local('result') = #a_string;
    
    iterate(#replacements, local('replace_set'));
        #result->replace(#replace_set->first, #replace_set->second);
    /iterate;
    
    return(#result);
/define_tag;

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

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