Click to See Complete Forum and Search --> : Creating repeating characters


cczernia
01-08-2008, 11:23 AM
I was wondering if there is a way to create repeating characters such as periods or dashes to repeat after a word. This would create a look that is popular on menus.

Example

Hamburger...................$3.00
Fries...........................$1.50
Steak and Eggs............$6.50

scragar
01-08-2008, 11:43 AM
var message = "Hello";
message = message.pad(".", 10);
alert(message);

cczernia
01-08-2008, 12:04 PM
Thanks for the reply but I can't seem to get .pad to work. I tested in both IE and Firefox. In Firefox I get "message.pad is not a function"

scragar
01-08-2008, 12:10 PM
sorry, forgot to post the function :P
String.prototype.pad = function(l, s, t){
return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2)) + this + s.substr(0, l - t) : this;
};