Andreas Leitgeb<avl@gamma.logic.tuwien.ac.at> writes:
I also wrote that my needs fortunately weren't all that general, so I got
by with a couple of stock pad-strings, of which I pick the needed one,
append it to the given string, and then do a .substring() on it. (it's
the chars '0' and '9' and a max len well below 20 *for my current needs*.
I can not come up with a better solution now, but would suggest
to hide this implementation behind an interface, so that you can
easily replace this implementation in all you projects, once this
is better supported in Java. Like,
interface/class MyStringUtils
{ /** Appends multiple copies of padCharacter to the source, so that
the result has lenght as its length when measured in Unicode code points. */
public java.lang.String pad
( java.lang.String source, java.lang.String padCharacter, int length );
... }
Then, go for the implementation that is most readable/maintainable first,
and only optimize it for run-time speed, /if/ this was shown to be
necessary.
Putting it in a reusable class makes a lot of sense.
as this.