1 Reply Latest reply on Jul 30, 2012 5:41 PM by robwoof

    Script: Truncating Text Values and search/replace text

    lkeyes

      I've got a situation where I've got a committee name and a church name that I want to truncate to use as a file name:

       

      "Committee On Formation" is an example, I"d like to truncate this to something like

      onformation.pdf

       

      1. Eliminate the "Committee" part of the string

      2. Truncate to a maximum of 14 letters. (Probably using Left function)

      3. Append ."pdf"

       

       

      "Colchester St. Andrew's"

      colchesterstan.pdf

       

      1. Strip out spaces and apostrophes

      2. Truncate to maxium of 14 letters (probably using Left function)

      3. append ."pdf"

       

      I know there is a combination of script steps and probably functions for this, but can't seem to put the right thing together.

       

      There is a field in the data table that contains the source string.

      I'm stroring the results in a variable - $FileName

       

      I don't have a problem with the truncation (step 2's above...); but I'm trying to figure out the first step in each example.

       

      ---- Larry

        • 1. Re: Script: Truncating Text Values and search/replace text
          robwoof

          Hi Larry,

           

          You could try using the Filter and Substitute functions, allowing only lower case letters, then truncate. So the calculation in your Set Variable step could look something like:

           

          Let ( [ fullName = Lower ( Committee Name ) ;

                   subName = Substitute ( fullName ; "committee" ; "" ) ;

                   filterName = Filter ( fullname ; "abcdefghijklmnopqrstuvwxyz" ) ;

                   shortName = Left ( filtername ; 14 ) ] ;

           

          shortName & ".pdf" )

           

          That calculation steps you through the process: convert to lower case, remove the word "committee" from the lower case version, remove any non-alphabetic characters and then truncate at 14 characters long. Finally it adds the ".pdf" extension. If you have FileMaker Pro Advanced, you could define a Custom Function with a text parameter to do it for you.

           

          HTH

          Rob