any way to count number of times a style is used?

  • For example: If I have a document that has two words in different parts of the document that are bolded; Is there an easy way to get a count of how many times the bold style was used in the document?

  • This works but it counts each letter as 1.

    So the word bold counts as 4 where if it is the only word that is bold in the document, it should count as just one. If there was another word that was bold somewhere in the document the count would be two.

    I'm trying to do something like this but not working yet.

    Code
    count := 0;
      With WPRichText1 do begin
        CPPosition := 0;
        repeat
          if afsBold in CPAttr.Style then inc(count);
            repeat
              CPMoveNext;
            until NOT afsBold in CPAttr.Style;
        until not CPMoveNext;
      end;

    Is this possible?

  • I think I got it, this seems to work.

    Code
    count := 0;
      With WPRichText1 do begin
        CPPosition := 0;
        repeat
          if afsBold in CPAttr.Style then inc(count);
            While afsBold in CPAttr.Style do CPMoveNext;
        until not CPMoveNext;
      end;