Search code examples
powerapps

How to add new line in string variable


I am trying to add array of string +value to other string variable along with new line('\n') in msflow.But that is not working. can any one please assist on this.

Here are the details:

  1. Test-string-> string with some value(A)
  2. Test-Array->Array of values["B","C"]

3.Test-Append->expecting result

AB

AC

current result

ABAC


Solution

  • Your question is tagged 'powerapps', but in the description you mention 'msflow' (Power Automate). Depending on which product you are talking about, you would approach it differently.

    In Power Apps, you can use the function Char(10) to add a new line to a string. So if you have a string variable and a collection with values, you can use something like the expression below:

    Set(testString, "A");
    Collect(testArray, "B", "C");
    Set(result, Concat(testArray, testString & Value & Char(10)))
    

    In Power Automate, it's not as simple, but I've found one alternative at this community post where you can use the expression below to have a new line character:

    json('{"NL":"\n"}')?['NL']
    

    So if you have your variables initialized as below:

    Power Automate - variable initialization

    You can append the new line inside an Apply to each block:

    Appending new line to each item in the array

    Hope this helps!