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

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