5 Replies Latest reply on Mar 20, 2009 11:18 AM by amixer

    leftwords and rightwords eliminating punctuation



      leftwords and rightwords eliminating punctuation


      Hello all, I'm totally new to the forum but have been dabbling in Filemaker Pro for several years.  I'm trying to write a script that will parse a phrase of text, determine how many words are in the phrase, and insert a carriage return halfway through, creating 2 lines from the one phrase.  Here's the problem I'm having:  I'm using Leftwords and Rightwords to select the different parts of these phrases.  The output of these two functions is eliminating all the punctuation in my original phrase, which is unacceptable.  I'm sure there's an easier and correct way to do this that will preserve my punctuation.  Can anyone lend a hand?  Here's the script I wrote to do what I was hoping to do:


      put hard CR in long line
      Paste [ subtitle::Subtitle entry ]
      [ Select ]
      Set Field [ subtitle::z; WordCount ( subtitle::Subtitle entry ) ]
      Insert Calculated Result [ subtitle::Text holder; LeftWords ( subtitle::Subtitle entry ; Round ( subtitle::z/2 ; 0) )  & "¶"  & RightWords
      ( subtitle::Subtitle entry ; subtitle::z - Round ( subtitle::z/2 ; 0) ) ]
      Copy [ subtitle::Text holder ]
      If [ (Length ( subtitle::Subtitle entry ) = (Length ( subtitle::Text holder ))-1) and WordCount ( subtitle::Subtitle entry ) = WordCount
      ( subtitle::Text holder ) ]
      Set Field [ subtitle::Pass; "PASSED" ]
      Clear [ subtitle::Fail ]
      [ Select ]
      Set Field [ subtitle::Fail; "FAIL" ]
      Clear [ subtitle::Pass ]
      [ Select ]
      End If 


          I paste the long line in the field Subtitle entry

      then I set the field z = to the word count of that line 

      Then I insert a calculated result into the field Text holder, taking LeftWords of the field Subtitle entry, and using the word count, z, divided by 2 and rounded to the next whole number, then inserting a carriage return and then taking right words of z- (round(z/2)).   Finally I copy the result with the carriage return and run a comparison of that field to the field subtitle entry to make sure they are the same.  The comparison requires the word counts to match and the character counts to match (I subtract the carriage return from the text holder to account for the extra character).  Frustratingly, all the punctuation disappears (commas, periods the works) in the text holder once I've split the text.  Any help would be appreciated! Thanks,




        • 1. Re: leftwords and rightwords eliminating punctuation

          Using LeftWords() and RightWords() should NOT eliminate ALL punctuation marks from the text*. Which version are you using?




          (*) It will, however eliminate the punctuation marks (and spaces) at the "boundaries", e.g.


          Let (

          text = " -alpha, bravo, charlie, delta, echo- "

          LeftWords ( text ; 3 )  & RightWords ( text ; 2 )



          returns: "alpha, bravo, charliedelta, echo"



          The correct way to split the text into two lines would be:


          Let ( [
          text = " -alpha, bravo, charlie, delta, echo- " ;
          splitPoint = Position ( text ; RightWords ( text ; 2 ) ; Length ( text ) ; -1 )
          ] ;
          Replace ( text ; splitPoint ; 0 ; ¶ )


          This returns:

          " - alpha, bravo, charlie, ¶delta, echo - "

          • 2. Re: leftwords and rightwords eliminating punctuation

            Thanks, that looks much more efficient, and you're exactly right I'm losing the leading and trailing punctuation.  The split point script you showed me looks much more efficient as well.  I'll puzzle it out and see if I can get it working.  Thanks for your help!


            • 3. Re: leftwords and rightwords eliminating punctuation

              Good. Note that the suggested solution is not perfect. It assumes that all punctuation before the onset of the first word of the second line belongs to the first line, so that:


              alpha, bravo, charlie, "delta", echo


              will be returned as:


              alpha, bravo, charlie, "

              delta", echo


              This could be eliminated by looking for the first space preceding the split-point and breaking the line there - PROVIDED it can be assumed that there will always be a space somewhere in-between any two words.


              • 4. Re: leftwords and rightwords eliminating punctuation

                Just a side note:


                I noticed "Paste" and "Insert calculated result" script steps in your first example. These steps work only if the target field is present on the current layout and "fail silently" if they aren't. If your using a recent version of filemaker, you should be able to use Set Field instead. With this step, you won't have this issue to deal with.

                • 5. Re: leftwords and rightwords eliminating punctuation

                  Thanks for both of your responses.  Yes I was thinking about trying to make sure the split point was a space.  I played around with the position script at work today, but I haven't gotten it to work right for me yet.  I'm missing something syntax-wise.  Anyway I'm going to take a more thorough crack at it before I come and ask more questions about it ;) .  Once I get that part working sufficiently I'll take a look at how to make sure the split point is on a space between words.  I think that is a safe assumption for what I want this to do. 

                     Regarding the insert calculated text and paste, Set field is a better option I know, but (I don't have FMP in front of me right now) I didn't recall if I could do a Set Field using a calculated result for the data to put in the field.  I probably can but old habits die hard.  Having never done much other than refer to the manual when I get stuck, I'm sure my scripting logic is not the most efficient ;).  Thanks for the tips!  I'll repost when I either succeed or get stuck.