I'm trying to write a custom function to recursively trim all leading and trailing spaces and carriage returns from a text field. Here's what I've got and it's not working and I can't figure out why...
Trim_sp_CR_recursive (text ; N)
x = GetAsText(text) ;
L = Length (x) ] ;
Case( Mod(L ; 2 ) = 0 ; L/2; Int((L/2) + 1))
) ] ; // Max # times function should trim.
N > 1 ; Trim_sp_CR_recursive(
TrimCharacters (Trim(text) ; "¶"; "both") ; // text
N - 1) // N
P.S. I'm using FileMaker 9. The CF TrimCharacters trims the leading and trailing carriage returns and that works fine.
TrimCharacters(text; trimCharacter ; side) =
Let ( [
leftChar = Left (text; 1) ;
rightChar = Right (text; 1) ;
remainderLength = Length (text) - 1 ];
(side = "left" or side = "both") and leftChar = trimCharacter ;
TrimCharacters (Right (text ; remainderLength) ;
trimCharacter ; side ) ;
(side = "right" or side = "both") and rightChar = trimCharacter ;
TrimCharacters (Left (text; remainderLength) ;
trimCharacter ; side) ;
Any and all help is appreciated!