Reference · Strings

repeat

signature
repeat(str, int) -> str

What 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

print(repeat("x", 0), repeat("ab", 1), repeat("", 5))print(len(repeat("é", 3)))
output
 ab 3

Errors

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 large
this one fails
print(repeat("ab", 100000000))
output
line 1: `repeat` count is negative or too large

Chaining

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      42

See also

join, slice, len, format_number

Thread
7Useful? Like it, or add to its thread below.

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