7 Replies Latest reply on Apr 1, 2013 12:46 PM by JackZhang

    How to delete the content in parentheses

    JackZhang

      Title

      How to delete the content in parentheses

      Post

           Need help. I have several parentheses in each text string, I would like to delete the contents in parentheses using calculation function. Does anyone know how to do it?

           I can delete the content in the first parentheses using the following sentences:

           Let ([x=Pedigree; s=Position (x; "(";1;1)-1;e=Position (x;")";1;1) + 1]; TrimAll (Left (x; s) & Right (x; Length (x) -e); 1; 1))

           But I don't know how to add loop to get rid of others.

            

        • 1. Re: How to delete the content in parentheses
          philmodjunk

               A looping calculation is best done with a custom recursive function. Do you have FileMaker Advanced?

               On the other hand, a looping script can be used in Regular FileMaker Pro to remove the parenthetical text.

          • 2. Re: How to delete the content in parentheses
            JackZhang

                 Thanks, PhilModJunk. I only have Pro12. Does Pro12 have custom recursive function? If using looping script, how to do it?

            • 3. Re: How to delete the content in parentheses
              philmodjunk

                   A custom function can only be created/edited with FileMaker Pro Advanced.

                   Loop
                       Exit Loop IF [ //Paired Parenthesis test here is true see calc given below ]
                       Set Field [ YourTable::Pedigree ; //Expression to remove one instance of parenthetical text here see below ]
                   End Loop

                   //Paired Parenthesis Test
                   Let ( [ t = YourTable::Pedigree ;
                             p1 = Position ( t : '"(" ; 1 ; 1 );
                             p2 = Position ( t ; ")" ; 1 ; 1 )
                            ];
                              p1 and p2 > p1
                          ) // Let

                   //Remove one instance of parenthetical text
                   Let ( [ t = YourTable::Pedigree ;
                             p1 = Position ( t ; "(" ; 1 ; 1 );
                             p2 = Position ( t ; ")" ; 1 ; 1 )
                            ];
                           Left ( t ; p1 - 2 ) & Right ( t ; Length ( t ) - p2 )
                          )

                   Note: I did not use trimAll in my calc to remove parenthetical text as it could remove extra spaces intentially entered into other parts of the text in the field.

              • 4. Re: How to delete the content in parentheses
                JackZhang

                     I don't know much about script. Should I copy all your above text and just replace the table name? Does "[//Paired Parenthesis test here is true see calc given below]" mean sth. or it is just a note here? Thanks!

                • 5. Re: How to delete the content in parentheses
                  JackZhang

                       Is this only for two parentheses? I have more than two parentheses.  

                  • 6. Re: How to delete the content in parentheses
                    philmodjunk

                         A script has to be performed to change the data in your file. You would, indeed, subsitute the name of your table (occurrence) for the "YourTable" used in the example script.

                         The calculations used in Exit IF and Set Field are complex and can't clearly be displayed in a listed script. I've listed the calculations I recommend below the listed script. You would put those two expressions, modified to refer to your table occurrence and fields names in place of where you see:

                         "//Paired Parenthesis test..."

                         and

                         "//Expression to remove one instance..."

                         The script would then be performed by selecting it from the scripts menu, clicking a button or via a script trigger such as the OnObjectSave script trigger.

                         You'd open Manage | Scripts to create this script for use with your database.

                         It will remove any number of parenthetical phrases from your text field as it keeps removing  the first such phrase until it can no longer find another correctly entered pair of enclosing parenthesis.

                         A final note that may avoid some trouble if you are new to creating a script:

                         When Setting up Set Field, there are two Specify buttons that must be clicked. To get Set Field [Table::Field ; Expression], add set field to your script and click the first button (specify target field). Select Table::Field from the list of fields. Do not click the specify button next to the repetition box. Click OK to close this dialog box. Now click the lower specify button (calculated result) and create the expression to the right of the semicolon (;). Do not try to type in the semicolon.

                    1 of 1 people found this helpful
                    • 7. Re: How to delete the content in parentheses
                      JackZhang

                           I got it. Thanks for the great help!