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 (34 votes) Log in to vote

Rob Poelking   Rob Poelking - Show more from this author
Kiza Solutions
https://kizasolutions.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 style="word-wrap: break-word;"> 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;"> <h3>Support this website.</h3> <p>This library has been a free commmunity resource for FileMaker users and developers for 20 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 action="https://www.paypal.com/donate" method="post" target="_top"> <div style="text-align: center"> <input type="hidden" name="hosted_button_id" value="UHA9QXALRVQDQ"> <input type="image" src="/filemaker-custom-functions/images/donate-button.png" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" width="258" height="73"> <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </div> </form> </div> </div> <div style="text-align: center;"> <footer>Other resources: <a href="https://www.zipwise.com/webservices">ZIP Code API</a> <a href="/sample-data">Sample data</a> <a href="mailto:brian@briandunning.com">Contact</a> </footer> </div><div id="donate_popup_30"> <div style="float: right;"><a href="javascript:void(0)" onClick="getElementById('donate_popup_30').style.display='none';getElementById('blackbottom').style.display='none';" class="cool_button" style="margin-top: 15px;">Nope</a></div> <h3>Support this website.</h3> <p>This library has been a free commmunity resource for FileMaker users and developers for 20 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 action="https://www.paypal.com/donate" method="post" target="_top"> <div style="text-align: center"> <input type="hidden" name="hosted_button_id" value="UHA9QXALRVQDQ"> <input type="image" src="/filemaker-custom-functions/images/donate-button.png" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" width="258" height="73"> <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </div> </form> </div> <div id="blackbottom"></div> </body> </html>