String array function Join
in some cases, I need to concatenate several references (variables) which have rather long names (or complex object structures).
The standard approach (Concat(...)) makes for a very long lines.
Since multi-line values aren't supported (another area for improvement), the current approach I use is to create an array of each segment, since each member of the array can be its own line.
Ideally I'd like to take that array and just Join(string[], "")... but currently I can't, so I'm forced to concat(var[0], "", var[1], "_", var[2]).
The inclusion of a JOIN function would SIGNIFICANTLY simplify the variable's definition.

Thank you for taking the time to vote for this item.
Could you please email us some more information on this scenario.
We would appreciate your feedback.
11 comments
-
Larry Dorman commented
I built on to Ximon Eighteen's suggestion. It's the best terrible solution I've found, so far. I was worried that the beginning and end of my data was at risk, so I added a beginning and ending element to make the search unique.
"myArray": [
"***",
"abc",
"def",
"ghi",
"***"
],
"myString": "[replace(replace(replace(string(variables('myArray')), '\",\"', ''), '[\"***', ''), '***\"]', '')]""exampleOutput1": {
"type": "String",
"value": "abcdefghi" -
victor commented
I strongly agree with this much needed feature. The scenario: I have a string parameters "Project-One-April-26". I want to create a string variable "ProjectOneApril26".
In JavaScript, all I need to do is run "Project-One-April-26".split('-').join(''). but I can't do that in ARM template because concat() does not allow merging an array of strings into a single string.
It would be very helpful to have a function that takes an array (or arrays) of strings, and concatenate all the strings into a single string as output. Thank you!
-
Parker Shelton commented
+1. We have a scenario where we need to call listKeys() on an unknown number of storage accounts, then concatenate the results together into a single JSON dictionary. Neither concat() or format() appear to work in this scenario with an unknown number of arguments and there's no for() equivalent to loop and append.
-
Anonymous commented
lol I can't believe there are a bunch of string methods, but the most common used: join is not there.Let's say I want to provide users with an array parameter, I don't know beforehand how many items it will contain. But I need to make them all into a string seperated by a character (like semicolon or comma).
AWS already got this: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-join.html
-
Hal commented
Constructing a Kusto query from multiple variables (e.g. serverName, database name, maxDurationThreshold, etc.)
The simple thing to do might be to simply update concat to treat a single array argument as an array whose members are to be joined.
concat(variables('myArray'))
-
Alexander Batishchev commented
Hi. I'd love to share my scenarios. Please provide an email address. Or ping alexbat internally. Thanks!
-
Alexander Batishchev commented
Any update on this?
-
Bryan Wood commented
@joep I agree, there is the 'split' function in the string functions, but there is no inverse function in the array/object functions to 'join'.
There should be a way to join that is native to the ARM template SDK. while @Ximon does have a decent solution, one would have to include this every time they need it in a function linked, nested or direct.
Copy and paste is not true code reuse. Its code rewrite.
-
Joep Joosten commented
@Ximon Eighteen, yes this works, but it doesn't look nice...
-
Joep Joosten commented
If you add split as an ARM template function, you'll also need a join...
-
Ximon Eighteen commented
There's still no join function but a recent addition was user-defined functions. With that we can do the following:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"lines": {
"type": "array",
"defaultValue": [
"one\n",
"two\n",
"three"
]
}
},
"variables": {
},
"functions": [
{
"namespace": "ximon18",
"members": {
"join": {
"parameters": [
{
"name": "lines",
"type": "array"
}
],
"output": {
"type": "string",
"value": "[replace(replace(replace(string(parameters('lines')), '[\"', ''), '\"]', ''), '\",\"', '')]"
}
}
}
}
],
"resources": [
],
"outputs": {
"test": {
"value": "[ximon18.join(parameters('lines'))]",
"type": "string"
}
}
}Does that help?