Reference · Strings
repeat
signature
repeat(str, int) -> strWhat it does
The text written a number of times in a row. It is the way to pad or rule a line, since
there is no sprintf.
Examples
print(repeat("ab", 3))print(repeat("-", 10))print(repeat("é", 3))output
ababab----------éééEdge cases
- Zero times is the empty string, once is the text itself.
- Repeating the empty string is the empty string, however many times.
- The result's length is the text's length times the count, in characters.
print(repeat("x", 0), repeat("ab", 1), repeat("", 5))print(len(repeat("é", 3)))output
ab 3Errors
A negative count, or a result past 100 million bytes, is a runtime error, not an error
value; so is a text that is not a string or a count that is not an int. A count from a
float is converted with int first.
this one fails
print(repeat("ab", -1))output
line 1: `repeat` count is negative or too largethis one fails
print(repeat("ab", 100000000))output
line 1: `repeat` count is negative or too largeChaining
In a pipeline the text comes first and the count is the argument:
print("ab" | repeat(2))print(" Hi " | trim | lower | repeat(2))let width = 8print(repeat(" ", width - len("42")) + "42")output
ababhihi 42See also
join, slice, len, format_number
Thread
Thread 0 posts
On repeat(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo