May 4, 200619 yr Name & Parameters: [color:red][big] MergeFieldsB ( text ; openBrac ; closeBrac ) [/big] Description: Much Better solution! Fills in Merge Fields embedded in a text string (<>). It works just like the Merge Fields you use in text in Layout Mode. You can also substitute other kinds of bracketing characters for the double greater than and lesser than signs, "<<" and ">>". For instance, you could use square brackets like this: "[Field]". This is a much more elegant solution than the other onethat I posted yesterday (MergeFields1 and MergeFields2). It just goes to show that if you spend too much time fiddling around instead of being productive, you might come up with something. (Yeah, and you might win the lottery, too.) Sample Input: <> <> Dear <>, This really works well! Cheers, Jake Results: Dr. John Jakob Jingleheimer Schmidt, Ph.D. 300 Broadway New York, NY 10239 Dear John Jakob This really works well! Cheers, Jake Recursive: yes Formula: Case ( PatternCount ( text ; openBrac ) > 0 ; Let ( subText = Let ( [ openP = Position ( text ; openBrac ; 1 ; 1 ) ; openP2 = Position ( text ; openBrac ; 1 ; 2 ) ; closeP = Position ( text ; closeBrac ; 1 ; 1 ) ; Lgth = Length ( openBrac ) ] ; Replace ( text ; openP ; closeP + Lgth - openP ; GetField ( Middle ( text ; openP + Lgth ; closeP - openP - Lgth ) ) ) //---end Let Function 2 ) ; MergeFieldsB ( subText ; openBrac ; closeBrac ) //---end Let Function 1 ) ; text //---end Case Function ) Required Functions: None Author(s) Jake Sterling Date: 05/04/06 Credits: Disclaimer: FM Forums does not endorse or warrantee these files are fit for any particular purpose. Do not post or distribute files without written approval from the copyright owner. All files are deemed public domain unless otherwise indictated. Please backup every file that you intend to modify.
May 4, 200619 yr Hi Jake, You might have your CF account for a missing bracket somehow. It looks like it's going into an infinite loop if the first bracket is missing. You could check my FieldSubstitute() CF on this from a couple years ago to see how I did it: http://fmforums.com/forum/showtopic.php?tid/120434/ It's not perfect when dealing with a missing end bracket, but at least it does give some indication to the user. I couldn't really come up with a way to indicate a missing start bracket, but I was able to avoid the infinite loop.
Create an account or sign in to comment