Skip to main content
The strrep function repeats a string a specified number of times with an optional delimiter. Use this function to generate test data, create patterns for matching, or build formatted strings with repeated elements.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, repeating strings typically requires custom functions or loops. APL’s strrep provides this functionality natively.
| eval repeated=mvjoin(mvappend("text","text","text"), "")
In ANSI SQL, you use REPEAT or REPLICATE depending on the database. APL’s strrep provides standardized string repetition.
SELECT REPEAT('text', 3) AS repeated FROM logs;

Usage

Syntax

strrep(value, multiplier, delimiter)

Parameters

NameTypeRequiredDescription
valuestringYesThe string to repeat.
multiplierintYesNumber of repetitions (1 to 1024). Values over 1024 are capped at 1024.
delimiterstringNoOptional delimiter between repetitions (default: empty string).

Returns

Returns the string repeated the specified number of times with optional delimiters between repetitions.

Use case examples

  • Log analysis
  • OpenTelemetry traces
  • Security logs
Create visual separators or formatting patterns for log output visualization.Query
['sample-http-logs']
| extend separator = strrep('=', 50)
| extend formatted_log = strcat(separator, '\n', method, ' ', uri, ' ', status, '\n', separator)
| project _time, formatted_log
| limit 5
Run in PlaygroundOutput
_timeformatted_log
2024-11-06T10:00:00Z================================================== GET /api/users 200 ==================================================
This query creates visual separators using repeated equal signs, making log output more readable and organized.
  • strcat: Concatenates strings. Use this with strrep to build complex repeated patterns.
  • strcat_delim: Concatenates strings with delimiters. Use strrep’s delimiter parameter as an alternative for repeated patterns.
  • strlen: Returns string length. Use this to calculate how many repetitions you need.
  • substring: Extracts parts of strings. Use this with strrep for complex pattern building.