Check out left pad or the two dozen other "utility" packages that could be done in a single line of code.