How to calculate font size (or scale) for a given area base on how long a string is?

I want to automatically resize (or rescale) a font to best fit a textbox base on the length of a string. I’m currently using TextMeshProUGUI but the docs don’t help me much.

just below font size option, you will find auto size option. that should do the trick