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.Splunk SPL users
Splunk SPL users
In Splunk SPL, repeating strings typically requires custom functions or loops. APL’s
strrep provides this functionality natively.ANSI SQL users
ANSI SQL users
In ANSI SQL, you use
REPEAT or REPLICATE depending on the database. APL’s strrep provides standardized string repetition.Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| value | string | Yes | The string to repeat. |
| multiplier | int | Yes | Number of repetitions (1 to 1024). Values over 1024 are capped at 1024. |
| delimiter | string | No | Optional 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.QueryRun in PlaygroundOutput
This query creates visual separators using repeated equal signs, making log output more readable and organized.
| _time | formatted_log |
|---|---|
| 2024-11-06T10:00:00Z | ================================================== GET /api/users 200 ================================================== |
List of related functions
- 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.