6 Replies Latest reply on Nov 8, 2013 1:05 PM by jwshelton22

    Capitalize first letter after each period

    jwshelton22

      Title

      Capitalize first letter after each period

      Post

           Here is sample block of text as a User might enter.

           concrete contractors are skilled in all phases of concrete to form foundations, roads, structures and bridges.

           contractors compete with general construction companies, unskilled labors (i.e.

           contractors from other trades and do it yourself home owners) and as well as freelance concrete workers)

            

           I am looking for calculation that will insure concrete, contractors and contractors begin with a cap C.

            

           Proper capitalizes the first letter of each word. I need some that capitalizes the first letter after each "."

            

           thanks,

           Jim

        • 1. Re: Capitalize first letter after each period
          philmodjunk

               You'd need a recursive calculation such as is most easily created in a custom function (Needs FileMaker Advanced) to loop through your text capitalizing those first words. A looping script could also serve.

               But even then, it would be tricky to do without ending up with I.E. in your text due to the trailing periods...

               Do you have FileMaker Advanced?

          • 2. Re: Capitalize first letter after each period
            jwshelton22

                 Yes, I have Filemaker Advanced.

            • 3. Re: Capitalize first letter after each period
              philmodjunk

                   Let's use a two stage process. Custom Function 1 preps the data for Custom Function 2 (recursive) then updates the result returned to get the desired result:

                   //Capitalize(Paragraph)
                   //
                   //This function calls CapitalizeList to capitalize the first letter of the first word of every sentence ending in a period and space.
                   //
                   Let ( [ TheList = Substitute ( Paragraph ; ["i.e." ; "§" ] ; [". " ; ¶ ] ) ;
                              TheList = CapitalizeList ( TheList )
                            ] ;
                            Substitute ( TheList ; [ "§" ; "i.e." ] ;  [ ¶ ; ". " ] )
                          ) // Let

                   //CapitalizeList (TheList)
                   //
                   //Capitalizes the first letter of the first word of each item in the return separated list of values.
                   //
                   Let ( [ FirstWord = LeftWords ( TheList ; 1 ) ;
                             L = Length ( FirstWord ) ;
                             FirstWord = Upper ( Left ( FirstWord ; 1 ) ) & Right ( FirstWord ; L - 1 ) ;
                             FirstSentence = GetValue ( TheList ; 1 ) ;
                             FirstSentence = FirstWord & Right ( FirstSentence ; Length ( FirstSentence ) - L )
                          ] ;
                             Case ( IsEmpty ( TheList ) ; "" ;
                                         List ( FirstSentence ; CapitalizeList ( RightValues ( TheList ; ValueCount ( TheList ) - 1 ) ) )
                                       ) // Case
                          ) // Let

                   I've tested these functions after defining them in the Known Bugs List database to be sure that they work. The Capitalize function could be enhanced to work with other sentence ending punctuation such as ! and ?.

              • 4. Re: Capitalize first letter after each period
                jwshelton22

                     How can in what is below, there be two TheList in the Let? When copying over to FMA as a Custom Function it wants a number or constant after CapitalizeList and before the (.

                      Let ( [ TheList = Substitute ( Paragraph ; ["i.e." ; "§" ] ; [". " ; ¶ ] ) ;
                                TheList = CapitalizeList ( TheList )
                              ] ;
                              Substitute ( TheList ; [ "§" ; "i.e." ] ;  [ ¶ ; ". " ] )
                            ) // Let

                • 5. Re: Capitalize first letter after each period
                  philmodjunk

                       You can use the same List variable as many times as you need as long as you don't need to use the value being replaced by the second use of the same list variable. The calculation evaluates from left to right top to bottom and so TheList is updated to receive a new value in the second line based on the value assigned to it in the first.

                       You are getting an error message because your file can't find the CapitalizeList custom function. You have to define that function first then define the Capitalize function.

                  • 6. Re: Capitalize first letter after each period
                    jwshelton22

                         It working.

                          

                         Thanks

                         Jim