#2537 How about: Str.mult() ?

SlimerDude Mon 23 May 2016

I often want a string that's the same character repeated, say for creating underlines for titles. Currently, the best way to do this is via Str.padl which is neither pretty nor obvious:

title := "Judge Dredd"
under := "".padl(title.size, '=')

echo(title)  // --> Judge Dredd
echo(under)  // --> ===========

Taking the lead from Python ( see here ), how about a mult operator on Str?

@Operator
Str mult(Int times)

Then I could do this:

title := "Judge Dredd"
under := "=" * title.size

A similar operator on Int may also be useful so you can sway the arguments around.

Or, if not the operator method, I think at the least, a Str.times() method would be useful:

under := "=".times(title.size)

brian Tue 24 May 2016

Actually always planned on that but never got around to it, but I pushed that

Login or Signup to reply.