How can I count the number of lowercase and uppercase letters in a string?

I have data tables in my Human UI project.
The columns widths will adapt to either the header text width OR the content width.
The problem is that there is no knowing in advance which will be the widest.
So I chose to add tildas to my header text to match the max. width of the column content.

Column width formatting

The problem is that my formula would need to adjust to the number of uppercase letters since they are wider than lowercase.
Is there a plugin/component that can sort uppercase and lowercase characters ?

There’s actually a DataGridLengthUnitType.Auto switch (from the internal code perspective) which bases sizes on both header and content… But Human UI doesn’t support it. Maybe Andrew forgot about it…

1 Like

I’m don’t know anything about Human UI, but the headline problem can be solved using some Python:

201204_UpperLowerCaseCount_GHPython_00.gh (3.2 KB)

5 Likes

Thanks !
This is a great help.

1 Like

Depending on what is in your text, you may need to count numbers and special characters (including spaces), which won’t show up as upper or lower case, as well…

Regards
Jeremy

2 Likes

Yes… I realize that to accurately evaluate the actual length of the text is a very difficult task.
It would require knowing the relative width of each and every ASCII character !

Let’s see if the auto-width issue can be sorted out…

You can also MeasureText

1 Like

Hey ! That’s awesome !
If only there was a component for that …
:smirk: