Software Venture Consulting

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

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


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:  

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

Ray Cologon, NightWing Enterprises
http://www.nightwing.com.au/FileMaker

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

Description:

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 BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

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.
e.g
"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 http://www.briandunning.com/cf/904 ? 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).

Regards,
Ray

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

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

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:
City/Location:
Comment:
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 2 + 8 =
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. ProperAllWords ( text )
  (Thu, Dec 14, 5:19pm)
2. MatchExist ( SourceTable.Field ; DestTable.Field ; ReturnField )
  (Thu, Dec 14, 1:07pm)
3. BVR_Format ( bvr )
  (Wed, Dec 13, 5:32pm)
4. NumberToHexadecimal(NumberValue)
  (Fri, Dec 08, 8:54am)
5. Get_BaseTable
  (Thu, Dec 07, 4:27pm)
6. JSONCreateVarsFromKeys ( json ; namespace )
  (Wed, Dec 06, 8:21pm)
7. GetTableNzme ( field )
  (Tue, Dec 05, 9:16pm)
8. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)

RSS Feed of Custom Functions