strjoin()
The strjoin() function joins each element of an array with a specified separator and returns the result as a single string.
Syntax
strjoin(SEPARATOR, ARRAY)
Parameters
SEPARATOR- A string constant to insert between each element of the array. Non-constant expressions are not allowed.
ARRAY- The array field or expression to join.
Description
The strjoin() function returns a string formed by joining the elements of ARRAY with SEPARATOR between each element.
- If
ARRAYisnull, the function returnsnull. - If
ARRAYis not an array or list, the function returnsnull. - If any element in the array is
null, the string"null"is included at that position. - If a non-constant expression is specified for
SEPARATOR, error code90781is raised. - If more than two arguments are provided, error code
90780is raised.
Error codes
| Error code | Description |
|---|---|
| 90780 | More than two arguments were provided. |
| 90781 | A non-constant expression was specified for SEPARATOR. |
Usage examples
-
Join a numeric array
json "{}" | eval result = strjoin(",", array(1, 2, 3)) | # result: "1,2,3" -
Join a string array
json "{'tags': ['a', 'b', 'c']}" | eval result = strjoin(" | ", tags) | # result: "a | b | c" -
NULL input
json "{'arr': null}" | eval result = strjoin(",", arr) | # result: null
Compatibility
The strjoin() function is available since before Sonar 4.0.