Count number of characters in title of post

Thank you for you answer but that’s not what I need. I already know how to truncate a text, what I need is to count the number of characters of a text string (the title of the post) and apply (or not) a custom css code depending of its length. I can’t truncate the title of the post, I need to show it as it is so the only way for it to not break my design when iy’s really long whould be to apply a custom CSS code to it and use a smaller font size.
I thought it could be done because I saw a “character_count” reference in that post.