Skip to content

Latest commit

 

History

History
126 lines (99 loc) · 3.06 KB

concat.md

File metadata and controls

126 lines (99 loc) · 3.06 KB
description ms.date ms.topic title
Reference for the 'concat' DSC configuration document function
01/17/2024
reference
concat

concat

Synopsis

Returns a string of combined values.

Syntax

concat(<inputValue>, <inputValue>[, <inputValue>...])

Description

The concat() function combines multiple values and returns the concatenated values as a single string. Separate each value with a comma. The concat() function is variadic. You must pass at least two values to the function. The function can accept any number of arguments.

The function concatenates the input values without any joining character. It accepts only strings or arrays of strings as input values. The input values must be of the same type. If you pass a string and an array to the same function, the function raises an error.

Examples

Example 1 - Concatenate strings

The configuration uses the concat() function to join the strings abc and def

# concat.example.1.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
  - name: Echo 'abcdef'
    type: Test/Echo
    properties:
      output: "[concat('abc', 'def')]"
dsc --input-file concat.example.1.dsc.config.yaml config get
results:
- name: Echo 'abcdef'
  type: Test/Echo
  result:
    actualState:
      output: abcdef
messages: []
hadErrors: false

Example 2 - Concatenate arrays of strings

The configuration uses the concat() function to return a combined array of strings from two arrays of strings. It uses YAML's folded multiline syntax to make the function more readable.

# concat.example.2.dsc.config.yaml
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: Echo ['a', 'b', 'c', 'd', 'e', 'f']
  type: Test/Echo
  properties:
    output: >-
      [concat(
        createArray('a', 'b', 'c'),
        createArray('d', 'e', 'f')
      )]
dsc config get --document concat.example.2.dsc.config.yaml
results:
- name: Echo ['a', 'b', 'c', 'd', 'e', 'f']
  type: Test/Echo
  result:
    actualState:
      output:
      - a
      - b
      - c
      - d
      - e
      - f
messages: []
hadErrors: false

Parameters

inputValue

The concat() function expects two or more input values of the same type to concatenate. Each value must be either a string or an array of strings. If one value is a string and the other an array, or either value isn't a string or array of strings, DSC raises an error when validating the configuration document.

Type:         [string, array(string)]
Required:     true
MinimumCount: 2
MaximumCount: 18446744073709551615

Output

When every inputValue is a string, concat()returns a single string with every inputValue concatenated together. When every inputValue is an array of strings, concat() returns a flattened array containing the strings from each input array.

Type: [string, array]