6 Replies Latest reply on Apr 19, 2009 7:57 PM by amixer

    clearing partial data from a large text field (FMP7)

    amixer

      Title

      clearing partial data from a large text field (FMP7)

      Post

      Hello all, I'm a longtime dabbler in FM and I know this script step should be pretty easy which is why it's frustrating me to no end that it's not working.  Here's what I'm doing. I have a large text field from which I use a script to grab the first few whole words that equal 45 characters or less.  I'm using a set field command to put this line in another text field.  I then wish to delete those words I put into the second text field from the first field.  I've tried using set selection, but for some reason it's not working.  I checked my start and end position variables and they are computing correctly, but the selection never gets created.  I have not tried using cut and paste simply because I don't want to be forced to have this particular layout up  when I'm running the script.  I also tried to employ the perform find/replace script step on the field, giving the find parameter as the words I just pasted into the scecond field and the replace parameter as "" (basically empty I figured).  No dice.  How can I accomplish this? What am I failing to realize that is stopping these script steps from working?  Any help would be appreciated. Thanks!

      -Andrew OS X 10.5.6

       

       

      here's the basic idea:

       

      Set Field [ textmanip::loopcount; 1 ]
      Set Field [ textmanip::y; 0 ]
      Loop
      If [ (Length ( LeftWords ( textmanip::text entry ; textmanip::loopcount ) ) > textmanip::charlen) = True ]
      Set Field [ textmanip::line 1; LeftWords ( textmanip::text entry ; (textmanip::loopcount - 1) ) ]
      Set Selection [ textmanip::text entry; Start Position: 1; End Position: Length ( LeftWords textmanip::text entry ; textmanip::loop
      count-1 ) ) ]

      Clear [ textmanip::text entry ]

      Exit Loop If [ IsEmpty ( textmanip::line 1 ) = False ] 

      Else
      Set Field [ textmanip::loopcount; textmanip::loopcount + 1 ]
      End If
      End Loop
       

       

      I haven't yet finished the whole script which is why it exits right now if line 1 is full.

       




        • 1. Re: clearing partial data from a large text field (FMP7)
          comment_1
             How about something simpler:

          Set Field [ textmanip::line 1 ; Let ( [
          words = WordCount ( Left ( textmanip::text entry ; 45 ) ) ;
          over = Length ( LeftWords ( textmanip::text entry ; words ) ) > 45
          ] ;
          LeftWords ( textmanip::text entry ; words - over )
          ) ]

          Set Field [ textmanip::text entry ; RightWords ( textmanip::text entry ; WordCount ( textmanip::text entry ) - WordCount ( textmanip::line 1 ) ) ]


          Note that any punctuation at the split points will be lost (as you know from your previous thread).





          • 2. Re: clearing partial data from a large text field (FMP7)
            amixer
               thanks for the response, your script makes sense to me, but unfortunately I need to somehow preserve all punctuation while I do this. I've been fooling with Left and trying to figure out a way to get Position to return a correct position including punctuation. I've been trying to apply Position when I'm trying to copy a certain number of words out of a field that comprise no more than 45 characters including punctuation. I started with a loop that looked a little like this:

            set loopcount = 0

            Loop

            if(Length(Leftwords(text, loopcount)) > 45

            set field receiver too Left(text; Position(text; Leftwords(text;loopcount -1);1;1)

            exit loop if(length(leftwords(text, loopcount)) >45

            Else

            loopcount = loopcount +1

             

            Obviously I don't have the right syntax, but this gives you an idea of what I'm trying to do. The problem I'm having in my head is how do I include punctuation. For example, if my text is = "alpha beta delta!" and in Position I use length with leftwords to get the number of characters to use with my left function, it's conceivable that I could get "alpha beta delta" and then in the next line "! and whatever is next" I need to keep sentences together punctuation-wise. Somehow I'm just having a brain block with how to do this. Can you or anyone give me another nudge in the right direction?
            Thanks,

            -Andrew

            • 3. Re: clearing partial data from a large text field (FMP7)
              comment_1
                

              Unfortunately, I don't have a universal solution for this, because punctuation is punctuation, and unless you are looking at it, it's hard to say whether it belongs to the previous word or the next one. As I already suggested in the other thread, a space between the words could be used as a reliable guide - provided there IS a space somewhere betwen the words. If you can be confident that such space will always be there, then you can find it and break the line exactly at that position.

               

               

              BTW, I am puzzled why you need to do this at all. It was only when I re-read the other thread, that I realized you're into subtitles. I believe any decent subtitling application will accept subtitles separated by a double carriage return, and break them up into lines automatically.

              • 4. Re: clearing partial data from a large text field (FMP7)
                amixer
                  

                Ironically, I've been working with several subtitling programs, and although one does this function (wraps the text based on line length so the two subtitle lines are balanced), it doesn't allow export of an stl text file with the carriage returns included. It only allows export of a TIFF based solution which isn't what I need. The other one has regular word wrap, but it ends up making the subtitles very unbalanced. The process of making them balanced is mostly manual and laborious and time intensive. Not good for the wrists.  The programs I have access to and have been using don't do this in a satisfactory manner.

                 

                    So there's no way to include trailing punctuation (i.e. if a word ends with a period there's no way to reliably break either before that word or after the period, or question mark or exclamation point etc.?) Is there any way to know if a whole word has been selected?  I was thinking about a more brute force approach where one uses a loop set selection and copy and paste to a strict validation field to use a trial and error method of copying and pasting words into a destination field.  If the paste goes over 45 chars, an error is thrown and we step back one character unless that divides a word. Again not sure if there's any way to do that. . . thanks for your continued help

                 

                • 5. Re: clearing partial data from a large text field (FMP7)
                  comment_1
                    

                  Well, it's been a while, so my recollection may be mistaken. I always did my breaking manually anyway, to make it easier to read.

                   

                  Back to the subject: it is certainly possible to include all punctuation, leading or trailing. The problem is telling the two apart. If all you have between two words are punctuation marks with no space, it takes a human (a literate one) to make the call. IMHO, you will very rarely encounter such situation in spoken word, so you could just go with the splitPoint being =

                   

                  Position ( text ; " " ; 46 ; - 1 )

                   

                  the top line =

                   

                  Left ( text ; splitPoint - 1 )

                   

                  and the remaining rext =

                   

                  Right ( text ; Length ( text ) - splitPoint )

                  • 6. Re: clearing partial data from a large text field (FMP7)
                    amixer
                      

                    thanks a lot, that worked perfectly!

                    -Andrew