10 Replies Latest reply on Dec 30, 2010 10:16 AM by philmodjunk

    Change case to sentence case

    aklobby

      Title

      Change case to sentence case

      Post

      I am trying to find out if there is a way in Filemaker Pro 11 to select text that is all caps and change it to sentence case where the first letter is capitalized but the rest of the sentence is lower case. Is this possible? The only options I see in the drop down menu are lowercase, UPPERCASE and Title Case. 

      Any help is appreciated.

      aklobby

        • 1. Re: Change case to sentence case
          philmodjunk

          This calculation should do it, but note its limitations:

          Let ( FirstWord = Leftwords ( YourTable::YourTextField ; 1 ) ;
                  Proper ( FirstWord ) & " " & Lower ( Right ( YourTable::YourTextField ; Length ( YourTable::YourTextField ) - Length (FirstWord) )
                )

          This assumes that there's a single sentence in your text field and that no words other than the first word should be capitalized. This may not be the case if your sentence contains proper nouns.

          • 2. Re: Change case to sentence case
            raybaudi

            Hi

            I think that a script along this one could solve:

            Set Field ["do not specify any field name here"; 
            Let(
            t = Middle ( Get ( ActiveFieldContents ) ; Get ( ActiveSelectionStart ) ; Get ( ActiveSelectionSize ) ) ;
            Substitute ( Get ( ActiveFieldContents ) ; t ; Upper ( Left ( t ; 1 ) ) & Lower ( Right ( t ; Get ( ActiveSelectionSize ) - 1 ) ) )
            )]

            Any selected text, after running the above script, will have the first letter capitalized and the rest in lower case.

            • 3. Re: Change case to sentence case
              aklobby

              Thanks for the responses, 

              I have tried the following calculation:

              Let ( FirstWord = Leftwords ( Issues Tracking::Synopsis ; 1 ) ; Proper ( FirstWord ) & " " & Lower ( Right ( Issues Tracking::Synopsis ; Length ( Issues Tracking::Synopsis ) - Length ( FirstWord) ) )

              and get an error message that there are too many "(" or ")"

              Am I missing something? 

              AK

              • 4. Re: Change case to sentence case
                philmodjunk

                It means I missed something! Embarassed

                Let ( FirstWord = Leftwords ( Issues Tracking::Synopsis ; 1 ) ; Proper ( FirstWord ) & " " & 
                        Lower ( Right ( Issues Tracking::Synopsis ; Length ( Issues Tracking::Synopsis ) - Length ( FirstWord) ) )
                       )

                • 5. Re: Change case to sentence case
                  aklobby

                  I can't seem to get either calculation to work. Thanks for trying. 

                  AK

                  • 6. Re: Change case to sentence case
                    philmodjunk

                    How doesn't it work? I tested my method to make sure it works before posting here so I know it works and Raybaudi's method should also work.

                    Describing how it fails for you might give us a clue that will get this up and working for you.

                    • 7. Re: Change case to sentence case
                      aklobby

                      I am very new to this so please bear with me. I may be missing something very basic. When I put in the calculation and then run the script, all it does is moves the second word in the sentence over a space. I am doing this as an "Insert Calculated Result" script. I am selecting the sentence and then running the script. 

                      Thanks

                      AK

                      • 8. Re: Change case to sentence case
                        njem

                        I don't have the details of this worked out but here's a general algorithm. Since it starts as uppercase, skip the first character and leave it upper case. There are Loop controls in scripting. Start off by getting the length of the string and save it in a var. Set another var CharPointer to 2. Get the character at location CharPointer with one of the text functions. Test it if it's a period. If so set another var CapComing to 2. Set the character to lower case and replace the original (if it's a period or space or something doing lower case won't hurt). Inc the var that's the character pointer, test if it's reached string length. Repeat loop until string length is reached. While processing each char if CapComing is > 0 decrement. If it happens to be 1, that's the start of a new sentence (two chars after a period) so leave it be.

                        • 9. Re: Change case to sentence case
                          philmodjunk

                          Don't use Insert Calculated Result. Instead, use Set Field. That may be the issue here.

                          You can also use this expression in a calculation field set to return text. That option leaves your original text unchanged, so it can be a useful way to compare the original to your reformatted text to see if it works the way you want before attempting to script it.

                          • 10. Re: Change case to sentence case
                            philmodjunk

                            On further testing, leave out the " " & part as this is what is inserting the extra space.

                            Here's a demo file you might want to check out:  http://www.4shared.com/file/uIXGnrRm/SentenceCase.html