Download Offline Documentation (includes source of script)
fill_String() - Sometimes, we need a string filled with specific count of characters. Here is my solution. I decided to use a loop construct against VarSetCapacity() and NumGet() function calls, because small values are a bit faster. Also, with a loop, we can pad any string with any length and are not restricted to one characters.
If you want to get just a specific count of source string without a base string where to add, then fill() works faster.
If you want to get just a specific count of a single character instead of a string any lenght, then fill_Char() works very fast on high amount of copies.
; Pad string with 3 leading zeros. MsgBox % fill(3) . 123 ; Default value is zero ('0'). ; >> Returns "000123"
; Add spaces at one character before end of string. MsgBox % fill_String(5, " ", "Hello World!", -1) ; >> Returns "Hello World !"
It is ready for stdlib, just save as fill.ahk.