You're viewing a comment by mjc and its responses.

mjc Permalink
February 09, 2009, 22:53

Another way to make n copies of a string s:

function repeat(n, s      , str)
{
   str = sprintf("%*s", n, " "); # make n spaces
   gsub(/ /, s, str); # replace space with s
   return str;
}

Another idiom I sometimes use is this to make a string of "-" to underline another string:

ul = str; # copy the string
gsub(/./, "-", ul); # replace each char with "-"
print str; # print the string
print ul; # underline it

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "coding": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.