Brian Dunning's FileMaker Custom Functions

RemoveExtraSpace ( field )

Changes multiple spaces into a single space

  Average rating: 4.6 (28 votes) Log in to vote

Michael Alexander   Michael Alexander - Show more from this author
none
no website

Share on Facebook Share on Twitter

  Sample input:
The quick brown fox
  Sample output:
The quick brown fox

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

Clean up input from users, making sure words in a string are separated by exactly one space.

 

Comments

Henry Iriawan   Henry Iriawan, HYBAN
Feb 9, 2010
Thank you for the custom function.

However, to make this running, the content of CF would be:

If (PatternCount(field; " ") = 0; field; RemoveExtraSpace(Substitute(field; " "; " ")))

your CF content can work well if you have rename CF to be "RemoveSpaceSpace (field)"
 
CouchCoder   CouchCoder, Germany
May 30, 2014
Sorry to say this is complete mess, even with Henry's correction.

Given that this CF is called RemoveExtraSpace, the code should be:

If (
PatternCount ( field ; " " ) = 0 ;
field ;
RemoveExtraSpace ( Substitute ( field ; " " ; " " ) ; " " )
)

I would also recommend to replace the parameter 'field' with 'text' which is more clear:

RemoveExtraSpace ( text )

If (
PatternCount ( text ; " " ) = 0 ;
text ;
RemoveExtraSpace ( Substitute ( text ; " " ; " " ) ; " " )
)
 
CouchCoder   CouchCoder, Germany
May 30, 2014
The mess continues, because double spaces are stripped in discussion posts.
Replace [Space] by spaces to get it right:

RemoveExtraSpace ( text )

If (
PatternCount ( text ; "[Space][Space]" ) = 0 ;
text ;
RemoveExtraSpace ( Substitute ( text ; "[Space][Space]" ; "[Space]" ) ; "[Space]" )
)
 
Jens Rasmussen   Jens Rasmussen, Greve, Denmark
Jan 21, 2016
This one worked for me, using _ as the space char.
--
Case (
PatternCount ( text ; "__" ) ; RemoveExtraSpace ( Substitute ( text ; "__" ; "_" ) ) ;
text
)
--

I prefer Case over If, and I like the defaultResult to be the case when there are no counts of the pattern of double space. Positive logic, in other words. If the text is faulty, fix it, otherwise let it be.
 

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: