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
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> <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> <p>Under construction. <a href="mailto:brian@briandunning.com">Email me your wish list</a> for improvements.</p> </div></body> </html>