strrep
This page explains how to use the strrep function in APL.
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.
Usage
Syntax
strrep(value, multiplier, delimiter)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
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 5Output
| _time | formatted_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.
Generate indentation patterns based on trace depth for hierarchical visualization.
Query
['otel-demo-traces']
| extend simulated_depth = 3
| extend indentation = strrep(' ', simulated_depth)
| extend formatted_span = strcat(indentation, ['service.name'], ': ', kind)
| project _time, formatted_span, trace_id
| limit 10Output
| _time | formatted_span | trace_id |
|---|---|---|
| 2024-11-06T10:00:00Z | frontend: server | abc123 |
| 2024-11-06T10:01:00Z | checkout: client | def456 |
This query creates hierarchical indentation for trace visualization by repeating spaces based on simulated span depth.
Generate test patterns for attack signature detection or create anonymization masks.
Query
['sample-http-logs']
| extend id_length = strlen(id)
| extend anonymized_id = strcat(substring(id, 0, 3), strrep('*', id_length - 6), substring(id, id_length - 3, 3))
| project _time, id, anonymized_id, status, uri
| limit 10Output
| _time | id | anonymized_id | status | uri |
|---|---|---|---|---|
| 2024-11-06T10:00:00Z | user123456 | use****456 | 403 | /admin |
| 2024-11-06T10:01:00Z | admin12345 | adm***345 | 401 | /api |
This query creates anonymized user IDs by replacing middle characters with repeated asterisks, maintaining partial visibility for analysis while protecting privacy.
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.