1 2 Previous Next 21 Replies Latest reply on Dec 17, 2009 8:03 AM by StellaLuna

    [FM8.5] Delete text between square brackets [] ?



      [FM8.5] Delete text between square brackets [] ?


      Hi guys,


      I'm trying since yesterday to find a way to delete all the text that's between square brackets [*] in a field.


      Obviously, i can't just use the Find/Replace box (CTRL+SHIFT+F) because AFAIK, you can't directly use wildcards in it, so i tried building a script.


      So far, i've found the way to find all the records with [something] in them with Set Field + Perform Find, but the replace part, i just can't find a way to do it.


      So basically, for exemple, i have fields that looks like this : 


      - This is a test [something to delete]

      - Another test [something else to delete]

      - And a third test [delete me]


      And i want it to look like this : 


      - This is a test

      - Another test

      - And a third test



      Need a little help here ? 9000 internets to whoever's helping me with this.


      And as mentionned in the title, this is for FM ver.8.5 (non Advanced) and i'm a newbie to all this (just been assigned to mess up with FM at work).


      Thanks !


        • 1. Re: [FM8.5] Delete text between square brackets [] ?

          Hi Joe, one possible way but keep in mind that if there are more than one left and one right bracket, it will break so you might want to also have calculation which checks it.  cPatternCheck calculation might be:

          PatternCount(text;"[" ) > 1 or
          PatternCount(text;"]") > 1  (this will produce 1 if it will break). After searching if you find no 1's then you can script it with this calculation



          Set Field script step would be:  set field (text) with


          start = Position(text;"[";1;1);
          end = Position(text;"]";1;1) + 1;
          string=Middle(text;start;end-start )




          added this ... you would put this script set field within a loop. if you need help with that let us know or you could use Replace Field Contents.  If there are more than one, you might consider custom function or run process twice (it will remove first string set each time it runs)

          • 2. Re: [FM8.5] Delete text between square brackets [] ?

            Pending whether you always have no more than one "[" and "]" and that they are in that order...



            You can looping through the records or use Replace Field Contents with a calc like:


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



            So when you have the string in the field: "This is a test [something to delete] do something" it should result in "This is a test do something"



            *Edit - Didnt see the prev post. Having posting issues with these forums for some reason.      

            • 3. Re: [FM8.5] Delete text between square brackets [] ?

              Sorry for the newb question, but how do i enter said piece of code ?


              So far, that's what i have in the script editor : 




              The piece of code, i guess i have to enter it in the "Replace Field Contents", so that's what i did : 


              - Double-clicked on Replace Field Contents

              - Clicked on "Specify"

              - And this is where i'm at a lost...


              I tried to paste the code (i tried both of those you gave me), but it didn't accepted it, so i removed all the extra carriage return and extra space and then it was working. However, when i tried to run the script after that, it didn't do anything.


              I think i'm missing a step here... ?

              • 4. Re: [FM8.5] Delete text between square brackets [] ?

                You need to specify the target field to be the one that you want to hold the end result. In the window that opens up when you hit 'Specify', you paste in the calc. However, you have to change where I have "YourField" in the calc to be the field that has the value: "This is a test [something to delete] do something".


                So if you want to replace a field called YourField and just strip out the stuff between the brackets, then your target field would be YourField as well as the Let statement in the calc having YourField as well since you are replacing the target which happens to also contain the source currently.


                Does that make sense?


                • 5. Re: [FM8.5] Delete text between square brackets [] ?

                  Well, that's exactly what i did and it's still doesn't work.


                  Let me tell you all the steps that i have in there, just to make sure i'm not missing something : 



                  1- Set Error Capture = On


                  2- Enter Find Mode = [Find Records = test::English: [[*]]


                  3-Set Field [test::English] = English with Repetition set to 1


                  4- Perform Find = [Find Records = test::English: [[*]]


                  5- If [Get( FoundCount) > 0]


                  6- Replace Field Contents = Specify target field checked with this code in it :


                  Let ( [ x = test::English;
                            s =Position ( x; "["; 1; 1 ) -1;
                            e =Position ( x; "]"; 1; 1 )
                          TrimAll ( Left ( x; s ) & Right ( x; Length ( x ) - e ); 0; 0 )


                  7- End If



                  And that's it. When i run the script, first it finds all the records with [something] in it, then it's asking me this : 



                  I tried the first option (which seems like it's returning the right string), but it doesn't change anything at all. So, i tried the third option, giving it the code just above and it doesn't work either.



                  So, what am i missing ? I feel such like a newb :P



                  Thanks a lot once again... :)



                  • 6. Re: [FM8.5] Delete text between square brackets [] ?
                       The third option using calculated result is the correct one. However, according to your screen there are 4 records that are found which it should replace. Are you sure that your found set contains the brackets? Deducing from your screenshot, it seems as though your first records contains "This is a test", which obviously does not contain a brackett. I would take a look at your found set when it pauses to  show you the dialog for replacing.
                    • 7. Re: [FM8.5] Delete text between square brackets [] ?

                      I'm 100% sure that it found the correct set of fields. I basically have the same record 4 times (i used the duplicate button to create a couple of 'em) with this text in the "English" field : This is a test [delete me]


                      Like i said, the bit in the screenshot where it says Permanently replace [...] with "This is a test" is, for me, an indicative that the code is working, but something else is preventing him from actually replacing all the fields, and i really don't have a clue what it is :(

                      • 8. Re: [FM8.5] Delete text between square brackets [] ?

                        A shot in the dark: perhaps if you turn error capture off, you will get an error message explaining what's wrong.

                        • 9. Re: [FM8.5] Delete text between square brackets [] ?

                          Oh good idea, but no error message :(


                          FM is really lacking a debugger... is there one in FM10 ?

                          • 10. Re: [FM8.5] Delete text between square brackets [] ?
                               You need advanced for the debugger.
                            • 11. Re: [FM8.5] Delete text between square brackets [] ?

                              I just bought FM10 Pro Adv.

                              I'll give the same script a whirl tonight and see why it's not working then.



                              Thanks for the answers, if someone else have an another idea tho, please share, but i'll come back here to post the answer so maybe someone will find the exact same solution to his problem while Googling :)

                              • 12. Re: [FM8.5] Delete text between square brackets [] ?
                                   You should divide the problem into smaller parts, and see what works and what doesn't - for example: can you perform Replace Field Contents… manually, can you run it on another field, etc. I would also create a new calculation field, using the same formula and observe the results.
                                • 13. Re: [FM8.5] Delete text between square brackets [] ?

                                  So, didn't had the time to play with this for a couple of days, just went back in it and...


                                  I tried a couple of ways to do it with a script, with no luck of course, so i tried to do it step by step like you mentionned and if i do it manually by giving him the piece of code with the "Replace Field Contents" via the menu "Records|Replace Field Contents", it's working !


                                  Now, why isn't it working when i shoot the same piece of code in a script is beyond me. Any ideas ? Is it a problem with focusing, maybeit needs to focus on the field first to actually do the replacing ?

                                  • 14. Re: [FM8.5] Delete text between square brackets [] ?
                                       Are you sure that you are referencing the same table occurence in your target as you are when manually doing it?
                                    1 2 Previous Next