概要
傳回合並值的字串。
語法
concat(<inputValue>, <inputValue>[, <inputValue>...])
描述
函 concat() 式會結合多個值,並傳回串連值做為單一字串。 以逗號分隔每個值。 函 concat() 式為 variadic。 您必須至少將兩個值傳遞至 函式。 函式可以接受任意數目的自變數。
函式會串連輸入值,而不需要任何聯結字元。 它只接受字串或字串數位做為輸入值。 輸入值的類型必須相同。 如果您將字串和數位傳遞至相同的函式,則函式會引發錯誤。
範例
範例 1 - 串連字串
組態會使用函 concat() 式來聯結字串 abc 和 def
# concat.example.1.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo 'abcdef'
type: Microsoft.DSC.Debug/Echo
properties:
output: "[concat('abc', 'def')]"
dsc config get --file concat.example.1.dsc.config.yaml
results:
- name: Echo 'abcdef'
type: Microsoft.DSC.Debug/Echo
result:
actualState:
output: abcdef
messages: []
hadErrors: false
範例 2 - 串連字串陣列
組態會 concat() 使用 函式,從兩個字串陣列傳回字串的組合陣列。 它會使用 YAML 的折疊多行語法,讓函式更容易閱讀。
# concat.example.2.dsc.config.yaml
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Echo ['a', 'b', 'c', 'd', 'e', 'f']
type: Microsoft.DSC.Debug/Echo
properties:
output: >-
[concat(
createArray('a', 'b', 'c'),
createArray('d', 'e', 'f')
)]
dsc config get --file concat.example.2.dsc.config.yaml
results:
- name: Echo ['a', 'b', 'c', 'd', 'e', 'f']
type: Microsoft.DSC.Debug/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]