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

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

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 Playground

Output

_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.

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 10

Run in Playground

Output

_timeformatted_spantrace_id
2024-11-06T10:00:00Z      frontend: serverabc123
2024-11-06T10:01:00Z      checkout: clientdef456

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 10

Run in Playground

Output

_timeidanonymized_idstatusuri
2024-11-06T10:00:00Zuser123456use****456403/admin
2024-11-06T10:01:00Zadmin12345adm***345401/api

This query creates anonymized user IDs by replacing middle characters with repeated asterisks, maintaining partial visibility for analysis while protecting privacy.

  • 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.

Other query languages