2 Replies Latest reply on Nov 18, 2013 12:59 PM by giosbob

    Determining If a Field Contains Any Formatted Text

    giosbob

      Hello,

       

      I need to know if a field contains any formatted text (italics, bold, underline, etc.) regardless of its position or content. By searching discussions on this website and others, I have discovered ways to format and unformat selected text and whole fields using various functions, but I have not found a function or script step that will return a "yes" or "no" to the question: does this field contain any formatted text, that is, does it use fonts that are not "regular."

       

      Any ideas or suggestions on how to do this?

       

      (My experience level is between novice and intermediate, so I apologize if the answer is obvious to more experienced FileMaker users.)

       

      Thanks,

       

      -Robert.

        • 1. Re: Determining If a Field Contains Any Formatted Text
          TomHays

          The GetAsCSS() function will let you know what formatting, if any, is present in a string. Thus you would use GetAsCSS() on the contents of the field.

           

          One approach to create a calculation to answer if the field contains any formatting (style, font, font size, or color) is to compare the results of GetAsCSS() on the original string to GetAsCSS() on the string stripped of any formattting.

           

          For example you can use this calculation where MyField is the field you are examining. 1 = field is unformatted. 0 = field has some formatting.

           

          Let(

          [original = MyField;

          Plain = TextFormatRemove(original)

          ];

          Case(

          Length(GetAsCSS(original)) = Length(GetAsCSS(Plain)); 1;

          0

          )

          )

           

           

          You could also compare the equality of GetAsCSS() results directly instead of checking the equality of the lengths, but I expect that just checking the lengths would be faster for larger strings.

           

          -Tom

           

           

          Addendum:

           

          If you trust that the default value of GetAsCSS() for unformatted strings won't change, you can use the fact that it simply adds 24 characters of CSS boilerplate to the original unformatted string. Any formatting will increase the length of the CSS.

           

          Let(

          [theField = MyField

          ];

          Case(

          Length(GetAsCSS(theField)) - Length(theField) > 24; 0;

          1

          )

          )

          1 of 1 people found this helpful
          • 2. Re: Determining If a Field Contains Any Formatted Text
            giosbob

            Hi,

             

            Thanks for your replies. As often happens, I have pulled in another direction for the last week. I will try to experiment with your suggestions over the next couple of days.

             

            -Robert.