Brian Dunning's FileMaker Custom Functions

text.Replace ( Text ; SearchText1 ; SearchText2 ; ReplacementText ) )

Replaces a text between two identifiers (including the identifiers)

  Average rating: 4.4 (33 votes) Log in to vote

Rob Poelking   Rob Poelking - Show more from this author
Excelisys, Inc.
http://excelisys.com

Share on Facebook Share on Twitter

  Sample input:
text.Replace ( xml ; "" ; "" ; ""
  Sample output:



FileMaker 9 Developer Reference<title><br> <pubdate>2008</pubdate><br> </book><br> </xml> </div> </div> </div> <div style="clear:both;"></div> <p>  Function definition:<span class="grayital"> (Copy & paste into FileMaker's Edit Custom Function window)</span> </p> <textarea name="textarea" class="codearea" readonly id="textarea" style="height: 250px;">/* Name: text.Replace Params: text SearchText1 SearchText2 ReplacementText Function: */ Let ( [ text = text; SearchText1 = SearchText1 ; SearchText2 = SearchText2 ; ReplacementText = ReplacementText ; Len = Length ( text ) ; Stop1 = Position ( text ; SearchText1 ; 1 ; 1 ) ; Stop2 = Position ( text ; SearchText2 ; 1 ; 1 ) + Length ( SearchText2 ) ; LChunk = Left ( text ; stop1 - 1 ) ; RChunk = Right ( text ; Len - Stop2 + 1 ) ; T = middle ( text ; stop1; Stop2 - Stop1 ) ; X = Replace ( T ; 1 ; Length ( T ) ; ReplacementText ) ; CleanText = LChunk & X & Rchunk ; checkSearchText1 = Patterncount ( RChunk ; SearchText1 ) ; checkSearchText2 = Patterncount ( RChunk ; SearchText2 ) ; Rmd = Getasboolean ( checkSearchText1 ) and getasboolean ( checkSearchText2 ) ]; LChunk & X & If ( Rmd ; text.Replace ( RChunk ; SearchText1 ; SearchText2 ; ReplacementText ) ; RChunk ) ) /* Notes: Substitutes for a block of text when only the start and end parts are know and the middle is unknown. Replace on sterioids. Rob Poelking */</textarea> <button id="copyBlock" class="cool_button">Click to copy</button> <span id="copyAnswer" class="redital"></span> <script type="text/javascript"> var textarea = document.getElementById( "textarea" ); var answer = document.getElementById( "copyAnswer" ); var copy = document.getElementById( "copyBlock" ); copy.addEventListener( 'click', function ( e ) { textarea.select(); try { var ok = document.execCommand( 'copy' ); if ( ok ) answer.innerHTML = 'Copied'; else answer.innerHTML = 'Unable to copy'; } catch ( err ) { answer.innerHTML = 'Unsupported Browser'; } } ); </script> <p> Substitutes a block of text when only the start and end parts are known and the middle is unknown. Replace on sterioids. </p> <p> </p> <h2>Comments</h2> <p><a href="/filemaker-custom-functions/account.php">Log in to post comments.</a> </p> <p> </p> <blockquote> <p class="redital">Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.</p> </blockquote> </div> <div id="support" style="max-width: 800px;"> <h1>Support this website.</h1> <p>This library has been a free commmunity resource for FileMaker users and developers for 15 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth:</p> <form id="form1" name="form1" method="post"> <select name="amount" id="amount"> <option value="5.00">$5</option> <option value="10.00" selected="selected">$10</option> <option value="15.00">$15</option> <option value="20.00">$20</option> <option value="25.00">$25</option> <option value="35.00">$35</option> <option value="50.00">$50</option> <option value="75.00">$75</option> <option value="100.00">$100</option> </select> </form> <div id="paypal-button"></div> <script src="https://www.paypalobjects.com/api/checkout.js"></script> <script> paypal.Button.render( { style: { size: 'small', tagline: false }, env: '', // 'sandbox' or 'production' client: { sandbox: 'AYWWhKxNdh7GjhfyNhq4h0feDRQsqepeEhHkHD1hootJyuPNQ0hxmhdf3T49Lc3qhPPf9jmUMTk_nQT3', production: 'AQPRbrw3dbvIbG4dCRGSw2r4dwOH8TUTDiqy3ngZv_aomVtb2NwBJltoOvZZpmlYdLZHzRQFsBBw1sq8' }, commit: true, payment: function ( data, actions ) { return actions.payment.create( { payment: { transactions: [ { amount: { total: document.form1.amount.value, currency: 'USD' } } ], redirect_urls: { return_url: '/filemaker-custom-functions/tip.php?x=43' } }, experience: { input_fields: { no_shipping: 1 }, presentation: { brand_name: 'BrianDunning.com FileMaker Custom Functions' } } } ); }, onAuthorize: function ( data, actions ) { // Make a call to the REST API to execute the payment return actions.payment.execute().then( function () { actions.redirect(); } ); }, onCancel: function ( data, actions ) { window.alert( 'Your transaction has been canceled.' ); } }, '#paypal-button' ); </script> </div> </div> <div style="text-align: center;"> <footer>Other resources: <a href="/error-codes">Error code reference</a> <a href="/sample-data">Sample data</a> <a href="mailto:brian@briandunning.com">Contact</a> </footer> </div></body> </html>