How to concatenate Strings in loop

I am trying to concatenate list of Strings to a Single String.   I have created a String called finalString  before the loop . This finalString should contain the concatenated String.   Here the Microflow within the loop returns a String for every object in the loop.   How can I concatenate all the Strings returned by the sub microflow in the loop into a Single String.   Also I need to place the final concatenated String  within the Sqaure Brackets.   Can anyone help me with this?
2 answers

You can initiate the variable before the loop with a default value of '['. Inside the loop you can concatenate using the change variable action, with a value of $finalString + $templateVar. After the loop you can finalize using a change variable action with a value of $finalString + ']'


Inside the loop your Change Variable action should be...

$finalString + $templateVar


After loop add an extra Change Variable for finalString to wrap the square brackets around the concatenated string.

'[' + $finalString + ']'


I hope this helps.