9 Replies Latest reply on Mar 7, 2011 11:43 AM by philmodjunk

    Specific "word" count



      Specific "word" count


      How can I count the number of specific words in a field. If I have a thousand words in a text field, and I want to know how many times the word "Airplane" appears. How would I do that? Any help would be greatly appreciated. Thanks

        • 1. Re: Specific "word" count

          What if there are "airplane" or "airplanes" ?

          • 2. Re: Specific "word" count

            Here's a script I came up with to help another poster insert a number after each instance of a word entered in the LoopingReplace::Word field. A small modification of it would result in returning the word count you want:

            Set Variable [ $Size; Value:Length ( LoopingFindReplace::Word ) ]
            Set Selection [ LoopingFindReplace::TextField; Start Position: 0; End Position: 0 ]
                   Set Variable [ $I; Value:$I + 1 ]
                   Perform Find/Replace [ Find: LoopingFindReplace::Word; Search operation: Find Next; Search settings: Forward, Match whole words only;
                           Search across: Current record/request; Search within: Current field ] [ No dialog ]
                   Set Variable [ $Start; Value:Get ( ActiveSelectionStart ) ]
                   Exit Loop If [ IsEmpty ( $start ) ]
                   Set Field [ LoopingFindReplace::TextField; Left ( LoopingFindReplace::TextField ; $start + $size - 1 ) & " " & $I &
                           Right ( LoopingFindReplace::TextField ; Length ( LoopingFindReplace::TextField ) - ( $start + $size ) + 1 ) ]
                   Set Selection [ LoopingFindReplace::TextField; Start Position: $start + $size + Length ( $I ) + 1; End Position: 0 ]
            End Loop

            • 3. Re: Specific "word" count

              Thanks... I didn't think of using the same script... I appreciate it.


              • 4. Re: Specific "word" count

                One last question.... I bet you have heard that before. What is the best way for me to implement this script? As conditional format, A script, a custom Function. As I stated... I am very new to this. I have watched all the Lynda training regarding Filemaker Pro, but te scripting is not sticking with me... Thanks


                • 5. Re: Specific "word" count

                  It's written as a script. You can place a button next to the Word field that runs this script when you click the button or you can use an OnObjectExit or OnObjectSave trigger selected for this field to run the script.

                  A custom function could be crafted to do this as a calculation, but the loop would have to be redesigned to work with a recursive function call instead of the loop End Loop structure that I've used here.

                  • 6. Re: Specific "word" count

                    I was able to use the script you provided me this evening. It worked great until it got to word 70. Then it began spacing. By the time it got to 400, the numbers were spaced 3 additional spaces. I removed the space from the quotes but it still continued doing the same thing. Do you have any suggestions? ThanksThis is how it started:

                    All communications cable, control and signal cable, power cable and hook-up wire shall2 have tinned stranded conductors for flexibility and corrosion resistance, and shall3 be rated for marine or mobile applications.
                       Hook-up wire shall4 conform to MIL-W-76B.
                       All power cable shall5 conform to Underwriters Laboratories

                    This is how it ended:

                    These lights shall b406e powered from the vehicle DC electrical system and switched in the cab and, in the case of an elevated cab or service point, at a point accessible from the ground.
           Signal Lights
                       The system shall b407e equipped with two amber strobe lights (one at each end of the system, mounted such that at least one is visible from any position).  The strobe light signals shall a408utomatically


                    • 7. Re: Specific "word" count

                      In my tests of this, (for not nearly so many repetitions of the same word ) I would have gotten a space between the word and the first digit of the inserted number. Did you modify the caculation I posted to change this? If so, how did you change it?

                      • 8. Re: Specific "word" count

                        After I seen what it was doing, I removed the space between the Quotation marks. Otherwise I have it as you sent me.

                        Once it reaches the number 70, it adds a space and then by the time it reaches 100 it adds three spaces.

                        • 9. Re: Specific "word" count

                          Doesn't it add a space when it reaches 10 not 70? The change that is occurring is the increase in digits in the counter which increases to two when $I is 10 and increases to 3 when $I reaches 100.

                          After first removing the space character and then removing the +1 from the following step to allow for the removal of the extra space character in the set field step,

                          Set Selection [ LoopingFindReplace::TextField; Start Position: $start + $size + Length ( $I ) ; End Position: 0 ]

                          I ran my demo file past 70 instances and didn't see any spacing issues.