How to remove whitespace right to a string based on its length?

This is for export to a txt file.

The idea is to simply count the number of chars $len(%genre%) and trim the corresponding white space chars to the right, so the right border aligns again.

 ___________________________________________
|   Artist: %artist%                        |
|   Genre:  Classical                             -->|
 ___________________________________________
|   Artist: %artist%                        |
|   Genre:  Classical                    <--|

Can someone help with this function?

I don't see a function.

The real, current code would help a lot.

Basically, you determine the length of the whole real string and then $repeat() a number of space characters in which you take the total position of the | and $sub() the length.

Here is a (German) thread that centers text:

The code should be readable, though