Merge ( )

Function stats

Average user rating
532
395
9999
Support
FileMaker 7.0 +
Date posted
16 July 2016
Version
1
Recursive function
No

Author Info
 David Moyer

6 functions

Average Rating None

author_avatar



 

Function overview

Prototype

Merge  ( text;   prefix;   suffix )


Parameters

text  The text string to be formatted


prefix  Applied to the beginning of non-empty text input


suffix  Applied at the end of non-empty text input


Description

Tags:  text formatting  

In my world, I invented this FM custom function that I've used more than almost any other function. It's mostly useful for keeping your calculations cleaner and easier to maintain.

It's for formatting text. I call it the "Merge" function; and I suspect some of my co-inventors chose the same name.

So, for those interested, this function very simply bookends your text with a text "prefix" and "suffix", as long as the text you supply is not empty. Otherwise, the function returns nothing.

So, if you don't have this one in your custom function list, please try it out.


Examples of use:

FullName = Merge ( NameFirst; ""; " " ) & NameLast

... prevents the extra preceding space when the first name field is empty



CustomerName & "¶" &

AddressLine1 & "¶" &

Merge ( AddressLine2; ""; "¶" ) &

City

... prevents the extra carriage return when there is no second address line

Examples

Sample input

"Sherlock " & Merge ( "the Hat" ; "(" ; ") " ) & "Holmes"


Sample output

Sherlock (the Hat) Holmes

 

Function code

If ( IsEmpty ( text );
"";
prefix & text & suffix
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/395

    Prototype: Merge( text; prefix; suffix )
    Function Author: David Moyer (http://www.fmfunctions.com/mid/532)
    Last updated: 16 July 2016
    Version: 1

*/
// ===================================

 

Comments

Fabrice
30 July 2016



in your example: Merge ( NameFirst; ""; " " ) & NameLast
What if NameLast is empty? You get a blank.
The native function to do this is: Trim ( NameFirst & " " & NameLast ).
If you work on more values, you can do :
substitute ( list ( nameFirst ; nameMiddle ; nameLast ) ; ¶ ; " " )

But indeed it's nice if you want to put in parenthesis, brackets or quotes.
  General comment

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (27)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (13)
Filter  (12)
Layout Objects  (11)
Design  (10)
Array  (8)