Brian Dunning's FileMaker Custom Functions

util.FormatWithMask ( text_to_format ; format_mask )

Format text with a simple mask using # as a placeholder for text in the mask

  Be the first to rate this function Log in to vote

Pip Meadway   Pip Meadway - Show more from this author
PIPCO IT

Share on Facebook Share on Twitter

  Sample input:
util.FormatWithMask ( "01234987654" ; "(#####) ######" )
  Sample output:
"(01234) 987654"

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This was inspired by the Mask () custom function by Geoffrey Gerhard here: https://www.briandunning.com/cf/872

I have used the FMP18 While () function to implement this rather than making it recursive.

The mask uses a hash character # to show where the text in the text to format is consumed - each # character consumes a single character from the text to format.

If the mask is longer than the text to format, then the return result is only as long as the text to format, conversely if the text to format is longer than the mask, then the return result is only as long as the mask.

e.g.

util.FormatWithMask ( "ABCDE" ; "#######" ) will return "ABCDE"
util.FormatWithMask ( "ABCDE" ; "###" ) will return "ABC"

Anything other than a # character is put into the result as is

e.g.

util.FormatWithMask ( "ABCDE" ; "Start=#-#-#-#-#=The end" ) will return "Start=A-B-C-D-E=The end"

If you need to include a # character as literal text, escape it using the backslash \ character

e.g.

util.FormatWithMask ( 12345 ; "\####-##" ) will return "#123-45"


 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

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: