Jump to content

MergeFieldsB ( text ; openBrac ; closeBrac )

This topic is 5697 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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!




Dr. John Jakob Jingleheimer Schmidt, Ph.D.

300 Broadway

New York, NY 10239

Dear John Jakob

This really works well!



Recursive: yes


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 

) ;  


//---end Case Function


Required Functions: None

Author(s):B Jake Sterling

Date: 05/04/06



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.

Link to comment
Share on other sites

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:


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.

Link to comment
Share on other sites

This topic is 5697 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.