Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages

Shopping Cart
Shopping Cart


Free Newsletter


Privacy Policy

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.


 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

Trim4 ( text )

Rate this function:  

  Average rating: 4.0  (71 votes)
  Discuss this Custom Function

Ray Cologon, NightWing Enterprises

Removes *all* leading and trailing white space from the supplied text, including tabs, carriage returns, spaces and non-breaking spaces.

Sample Input:
Trim4 (" ¶¶Your text here ¶ ")
Sample Output:
Your text here

 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed


FileMaker's built-in Trim( ) function does a great job of removing spaces from the beginning or end of a value, but it does not deal with other types of 'white space' characters such as tabs and carriage returns.

Other functions such as the LeftWords( ) function will remove tabs abnd CRs, but also take out punctuation, leading decimals, bullets and dashes etc.

This function operates recusively to remove any or all of the four characters:

- space
- non-breaking space
- carriage return
- tab

from leading and trailing positions around the supplied text. I've named it Trim4 because it explicitly removes leading/trailing occurrences of four characters.

Note1: The first parameter of each of the PatternCount( ) functions contains the four targeted characters (space, nbrspace, tab, CR).

Note2: To address an issue that occurred when copying the original function (some browsers rendered non-breaking space as regular spaces), a revised version has been posted above. This version requires FIleMaker 10 or later, as it uses the Char( ) function to explicitly render the characters mentioned in Note 1 above.

Note3: If you wish to use the revised version of the Trim4( )function with a version prior to 10, you'll need to re-define the sT variable with a literal string containing the corresponding characters (tab, return, space and non-breaking space respectively). Or find someone with a copy of an earlier version of the function... ;)

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

This is my Custom Function and I want to edit it


5 most recent comments | Show all 36 comments

Excellent - just what I needed!

Mike Scott, Liverpool
July 10, 2014 7:45am

Yes, its a really a nice one. But sometimes we need a specific no of carriage retuns from our text (not at leading and trailing ). lets look at the below example.
"1¶2¶3¶4¶4¶¶4¶¶¶¶¶¶¶¶5¶¶¶¶¶¶¶¶¶ ¶¶6¶¶¶¶" text needs to be converted to "1¶2¶3¶4¶4¶4¶5¶6".
So for this we have to use one additional function to do the same.

Function: Substitute ( Text ; ["¶¶" ; "¶#"];["#¶";""] ;["#";""] )
Where "Text" is the input string.

It only replces the multiple carriage retuns within the text to a single one. If will not replaces the leading and trailing carriage returns. SO we have to pass this functin into the Trim4(text) custom function.

abhaya, BBSR
August 22, 2014 12:25am

What are your thoughts on the similar non-recursive method used in Supertrim, by Debi Fuchs, found at ? I'm wondering if you know of an advantage to the algorithm used here?

Dan Shockley, New York, NY
March 31, 2015 12:27pm

Hi Dan,

The function Debi came up with is great and, since it exploits native functions, would work well for heavy lifting applications (i.e. processing large amounts of text).

The Trim4 example shown here is a subset of a suite of functions including a master function (not published here) that uses the same concept to trim any string of characters from leading/trailing positions (by supplying the sT variable at runtime via a second function parameter) - so in that sense the recursive approach I took here offers some added flexibility and the ability to more easily reapply the logic to other related tasks.

Both have their uses and together they demonstrate the flexibility of the platform (i.e. there are multiple viable solutions to most problems in FileMaker).


Ray Cologon, Melbourne, Australia
April 01, 2015 7:27am

Simple and elegant, what else could we ask? =D

Paco Baez, Adeliade, Australia
July 21, 2016 11:28pm

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 7 + 7 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions