Created
March 29, 2011 22:45
-
-
Save rafaelrinaldi/893516 to your computer and use it in GitHub Desktop.
Repeats a character how many times you want.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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}" | |
} |
Ruby is awesome. I always postpone to do something with it...
I hope I can find time to learn more "after the rain".
a ruby script:
#!/bin/env ruby
puts ARGV[0] * ARGV[1]
ActionScript:
function repeat( p_string : String, p_times : Number ) : String {
return Array([].length = p_times).join(p_string);
}
Another version: https://gist.github.com/1101070
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in ruby
repeat() {
ruby -e "puts "$1" * $2"
}