Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created March 29, 2011 22:45
Show Gist options
  • Save rafaelrinaldi/893516 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/893516 to your computer and use it in GitHub Desktop.
Repeats a character how many times you want.
#
# Repeats a character how many times you want.
#
# $1 The character you want.
# $2 How many times you want.
#
repeat() {
character=$1
times=$2
string=$(printf "%""$times""s")
echo "${string// /$character}"
}
@azisaka
Copy link

azisaka commented Mar 30, 2011

in ruby

repeat() {
ruby -e "puts "$1" * $2"
}

@rafaelrinaldi
Copy link
Author

Ruby is awesome. I always postpone to do something with it...
I hope I can find time to learn more "after the rain".

@azisaka
Copy link

azisaka commented Mar 30, 2011

a ruby script:

#!/bin/env ruby

puts ARGV[0] * ARGV[1]

@rafaelrinaldi
Copy link
Author

ActionScript:

function repeat( p_string : String, p_times : Number ) : String {
return Array([].length = p_times).join(p_string);
}

@rafaelrinaldi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment