RemoveExtraSpace ( field )
Changes multiple spaces into a single space
Average rating: 4.6 (28 votes) Log in to vote
Michael Alexander - Show more from this author
none no website |
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, 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, 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, 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, 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. |
||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.