Brian Dunning's FileMaker Custom Functions

TrimInvalidTrailingChars ( invalidChars ; textToTrim )

Trim given characters if they occur at the tail of a string

  Average rating: 4.5 (2 votes) Log in to vote

Benjamin Storrier   Benjamin Storrier - Show more from this author
Studio Mondo
http://www.studiomondo.com.au

Share on Facebook Share on Twitter

  Sample input:
TrimInvalidTrailingChars ( "-" , "testString--" )
  Sample output:
testString

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

Ensure specific characters never appear as the last character in a string by trimming them off using this handy function.

- Handles multiple illegal characters given to the function as a string.
- Recursively trims illegal trailing characters until a legal one is found.

 

Comments

19752   19752, fmc
Apr 8, 2018
It can be non-recursive.

Let ( [
~lastCharIsValid = Right ( Substitute ( textToTrim ; invalidChars ; "" ) ; 1 ) ;
~lastPositionOfValidChar = Position ( textToTrim ; ~lastCharIsValid ; Length ( textToTrim ) ; -1 )
] ;
Case (
~lastCharIsValid = "" ; "" ;
Left ( textToTrim ; ~lastPositionOfValidChar )
)
)
 

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 15 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: