7 Replies Latest reply on Jul 22, 2014 9:26 AM by DrewTenenholz

    Custom Function to Recursively Trim Text...

    carolej

      Hi -
      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)

      Let ([

      N =

      Let ([

      x = GetAsText(text) ;

      L = Length (x) ] ;

      Case( Mod(L ; 2 ) = 0 ; L/2; Int((L/2) + 1))

      ) ] ; // Max # times function should trim.

      Case (

      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 ];

      Case (

      (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) ;

      text

      ))

       

       

      Any and all help is appreciated!

       

      Carole