1 2 Previous Next 24 Replies Latest reply on Jul 23, 2015 4:02 AM by richardsrussell

    How can I prevent titlecase from being applied to certain words?

    jgalt

      I have a data that is being supplied by a third part in all uppercase. I would like convert it to titlecase but I would like the abilty to force certain text strings to be all lowercase and others to be all UPPERCASE.

       

      For example, I would like to end up with:

      "Acme Widgets of CA"

      not

      "Acme Widgets Of Ca".

       

      This seems like a pretty challenging task. Is there a reasonable way to do this?

       

       

      Could I do something like this?

       

      Convert these two letter strings that begin with a space to lowercase but do not convert them if they are parts of words such as "attack, issue, office".

      " at"

      " is"

      " of"

       

      Similarly, I need to convert all state abbreviations to uppercase without affecting words that begin with these strings, such as "Cancer, Flowers, Water".

       

      " CA"

      " FL"

      " WA"

        • 1. Re: How can I prevent titlecase from being applied to certain words?
          davehob

          I use a custom function called "SmartProper", which does a pretty good job of this.  It's easily customisable (you can add "CA", for example, as an exception), and names like O'Connor and McDonald.  I think I found it on the Brian Dunning site.  (Note, though, that it's not the same as "SmarterProper", which I also tried and found to be not as good.) 

          Dave.

          • 2. Re: How can I prevent titlecase from being applied to certain words?
            davehob

            Sorry, I realise that the CF that I'm calling "SmartProper" is actually my customised version of the CF called "Title", which was written by Howard Schlossberg, and is available here.  I've tested your examples and, with a bit of tweaking, it returns the results you require.

            • 3. Re: How can I prevent titlecase from being applied to certain words?
              richardsrussell

              I was gonna say "looks like a job for a custom function", but I see from Dave Hobson that not only has someone else come to the same conclusion, they've gone ahead and created it.

               

              Thus I'll only add that the great thing about custom functions is that they're way easier to copy from one solution to another than some functional equivalent that's embedded in a field definition. In fact, I keep a small document that contains only the essential components of a custom function, one above the other, so I can copy the whole thing, paste it into the calculation box of the CF dialog, and from there cut and paste the function name and parameters into their respective slots in that same dialog box. Here, for example, is what I've got on file for my "Dollarize" CF:

               

              = = = = = =

              Dollarize

               

              Amount

               

              Case (

                IsEmpty ( Amount ); "";

                Amount = 0; "$0";

                Amount < 1; Amount * 100 & "¢"; /* .25 = 25¢ */

                Amount = Truncate ( Amount; 0 ); "$" & Amount; /* 8 = $8 */

                Int ( Amount * 10 ) = Amount * 10; "$" & Amount & "0"; /* 8.5 = $8.50 */

                "$" & Amount /* 8.95 = $8.95 */

              )

              • 4. Re: How can I prevent titlecase from being applied to certain words?
                flybynight

                This may not be exactly what you are looking for, but we found it to be one of those "brilliant in its simplicity" things.

                Found this nugget in the deceptively named "White Paper for FMP Novices" which can be found at Foundation Database Systems. We have incorporated it into our Reformat CF with some other options.

                If (Exact(Text; Lower(Text)); Proper(Text); Text)

                Basically, this takes anything that the user enters as all lower case and makes it proper. If they have done any capitalization, then we trust their judgement and leave it alone.

                It won't fix your specific example, but it is an easy fix for names like O'Connor, where it won't incorrectly "fix" what a user has specified.

                • 6. Re: How can I prevent titlecase from being applied to certain words?
                  davehob

                  I think I have included the link?  (If you mean my customised version, it's just Howard's original, with some mainly UK-centric exceptions, like BBC, BHS, etc.  Best for jgalt to start with the orginal I think.)

                  Dave.

                  • 7. Re: How can I prevent titlecase from being applied to certain words?
                    jgalt

                    Dave Hobson wrote:

                     

                    Sorry, I realise that the CF that I'm calling "SmartProper" is actually my customised version of the CF called "Title", which was written by Howard Schlossberg, and is available here.  I've tested your examples and, with a bit of tweaking, it returns the results you require.

                     

                    Thanks very much for pointing out this custom function. It looks great. I had searched briandunning.com looking for a solution but I was searching for the term "titlecase" which did not return any viable options.

                    • 8. Re: How can I prevent titlecase from being applied to certain words?
                      jgalt

                      flybynight wrote:

                       

                      This may not be exactly what you are looking for, but we found it to be one of those "brilliant in its simplicity" things.

                      Found this nugget in the deceptively named "White Paper for FMP Novices" which can be found at Foundation Database Systems. We have incorporated it into our Reformat CF with some other options.

                      If (Exact(Text; Lower(Text)); Proper(Text); Text)

                      Basically, this takes anything that the user enters as all lower case and makes it proper. If they have done any capitalization, then we trust their judgement and leave it alone.

                      It won't fix your specific example, but it is an easy fix for names like O'Connor, where it won't incorrectly "fix" what a user has specified.

                       

                      Thanks for sharing. I love the simplicity of it.

                      • 9. Re: How can I prevent titlecase from being applied to certain words?
                        keywords

                        Another method you might like to consider, which is activated on entering a field with auto-formatting applied, when there is already content in there. This approach has the advantage that you don't have to second-guess what the intentions of the user may be—if they really intend to enter tExT LiKe tHiS they can.


                        script name: set $thisField variable

                         

                        # activated OnObjectEnter to captures existing contents of a field for use in an internal autoenter formatting calculation

                        If [ IsEmpty ( Get ( ActiveFieldContents ) ) ] Exit Script [ ]

                        End If

                        Set Variable [ $thisField; Value:Get ( ActiveFieldTableName ) & "::" & Get ( ActiveFieldName ) ]

                        Show Custom Dialog [ Title: "Just checking ..."; Message: "This field already contains data. Do you wish to alter it or replace it?¶ —click CANCEL to leave unchanged"; Default Button: “Alter”, Commit: “No”; Button 2: “Replace”, Commit: “No”; Button 3: “CANCEL”, Commit: “No” ]

                        If [ defaultButton // choose to ALTER data ]
                        Set Field [ <yourTableName>::<yourField> ; Get ( ActiveFieldContents ) ]

                        Else If [ secondButton // choose to REPLACE data ] Set Field By Name [ $thisField; "" ]

                        Else If [ thirdButton // choose to CANCEL action ] Set Field [ <yourTableName>::<yourField> ; "" ] GotoField[ ]

                        End If

                        • 10. Re: How can I prevent titlecase from being applied to certain words?
                          jgalt

                          Dave Hobson wrote:

                           

                          Sorry, I realise that the CF that I'm calling "SmartProper" is actually my customised version of the CF called "Title".

                           

                          I think "SmartProper" is a much better name. A few months from now I am not going to remember what the "Title" function is for.

                          • 11. Re: How can I prevent titlecase from being applied to certain words?
                            jgalt

                            Does anyone know what I would need to change is this custom function so the word "at" at the end of this string is lowercase? It handles it properly when it is in the middle of the sentence but not at the end.

                             

                            Pembroke Gardens, The Shops At

                            Forum Shops at Caesars, The

                             

                            Also...what does he mean by "LeaveEmpty"? Am I supposed to replace "LeaveEmpty" with two double quotes?

                             

                            FileMaker Custom Function:Title ( Text ; LeaveEmpty )

                            • 12. Re: How can I prevent titlecase from being applied to certain words?
                              davehob

                              Hi.  Yes, two double quotes in "LeaveEmpty" - it's used for the initial population of PrevText in the recursion.

                               

                              Re. "at" at the end, yes I agree, it doesn't cope with this. For some reason it assumes that any of the "always lower" values can't be at the end of the string - it needs "next text" to make it honour the "always lower" list.  I've made it work, by excluding a line in the bit that deals with "always lower", but I'm a bit worried that I may have made it NOT work in other situations.

                               

                              Anyway. the screen shot below shows where I've amended it - but I haven't tested it in all situations, nor do I fully understand everything that's going on in here!

                               

                              smartproper.jpg

                              • 13. Re: How can I prevent titlecase from being applied to certain words?
                                user19752

                                Removing

                                 

                                WordCount( nextText ) > 1 and

                                 

                                will do it.

                                 

                                Yes, use "" always calling the function. It is used internally for recursive call.

                                • 14. Re: How can I prevent titlecase from being applied to certain words?
                                  jgalt

                                  Thanks for your replies. I removed

                                   

                                  WordCount( nextText ) > 1 and

                                   

                                  and that did the trick.

                                  1 2 Previous Next