concat

摘要

返回组合值的字符串。

语法

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

说明

函数 concat() 合并多个值,并将串联的值作为单个字符串返回。 用逗号分隔每个值。 函数 concat() 为可变参数。 必须至少向函数传递两个值。 函数可以接受任意数量的参数。

函数连接不带任何联接字符的输入值。 它仅接受字符串或字符串数组作为输入值。 输入值的类型必须相同。 如果将字符串和数组传递给同一函数,该函数将引发错误。

示例

示例 1 - 串联字符串

配置使用 concat() 函数来联接字符串 abcdef

# 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

示例 2 - 连接字符串数组

配置使用 concat() 函数从两个字符串数组返回组合的字符串数组。 它使用 YAML 的折叠多行语法使函数更具可读性。

# 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

参数

inputValue

concat() 函数需要连接两个或更多个相同类型的输入值。 每个值必须是字符串或字符串数组。 如果一个值是字符串,另一个值是数组,或者其中一个值不是字符串或字符串数组,则 DSC 在验证配置文档时会引发错误。

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

输出

如果每个 inputValue 都是一个字符串, concat()则 返回一个字符串,其中每个 inputValue 连接在一起。 如果每个 inputValue 都是字符串数组, concat() 则 返回包含每个输入数组中的字符串的平展数组。

Type: [string, array]