Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Solution
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

How to replace new line (‘\n’) in a Power Automate expression

Posted on April 11, 2021July 30, 2021 by Tom

“I can’t figure out how to replace a new line (‘\n’) or any other non-printable character in Power Automate expression.”


The Power Automate expression replace(…) doesn’t work as you might expect for some non-printable characters, e.g. new line. The first thing you’d probably try is to replace ‘\n’. But Power Automate won’t process it as a new line, it’ll process it as it is: \n string. Replace(‘string’, ‘\n’, ”) will replace only the substring \n in the whole string. If the substring is not found, it’ll not replace anything and the flow will continue. To replace a new line you must use the right ‘new line’ character in your flow.

Store ‘new line’ in a variable

One of the solutions is to store the ‘new line’ into a variable and then use that variable in the replace(…) expression. Initialize a String variable, and in the ‘Value’ just press Enter. That’ll create a variable with a character representing a ‘new line’.

New line variable

You can then use this variable in the replace(…) expression to replace new lines, e.g. with a semicolon.

replace(outputs('Compose'),variables('var_newLine'),';')
Power Automate replace new line variable

Get the ‘new line’ from an expression

Another approach, if you don’t want to create an extra variable in your flow, is to get the ‘new line’ from an expression. You can get the ‘new line’ character by a conversion from its percent-encoded (Uri) value ‘%0A’ via decodeUriComponent(‘Uri value’) expression.

decodeUriComponent('%0A')

Instead of initializing a variable, you use decodeUriComponent(…) directly in the replace(…) expression. The example below will replace new lines with a semicolon.

replace(outputs('Compose'),decodeUriComponent('%0A'),';')
Power Automate replace new line expression

Note: some files created in Windows use \r\n instead of just \n as the ‘new line’ value. If you end up with \r in your string in place of the new lines, try to replace the whole \r\n substring:

decodeUriComponent('%0D%0A')

Summary

Since this blog’s motto is “From no-code to low-code”, my preference is the expression. It’s not only reducing number of variables, but I’d consider it even safer to manage (“Why has the variable no value? I think I’ll delete it…”).

Also, the expression is not limited only to the ‘new line’ character. You can use the decodeUriComponent(…) for any problematic character, e.g. apostrophe. Instead of many apostrophes (as used e.g. in the Filter Query with apostrophes), you can decode the ‘%27’ value anywhere in your flow. You just need to find the percent-encoded value to replace.


πŸš€ Master Power Automate

Join 2,100+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

30 thoughts on “How to replace new line (‘\n’) in a Power Automate expression”

  1. Ben says:
    April 13, 2021 at 3:09 pm

    Good tip! I’ve run into this before and ended up using the variable method, but the expression makes a lot of sense.

    Reply
  2. Roberto says:
    April 16, 2021 at 2:48 pm

    Great find. Wanted to share that if the output is from the Create CSV Table action then the following worked for me:
    replace(body(‘Create_CSV_table’),decodeUriComponent(‘%0D%0A’),’;’)

    The \r\n is successfully replaced with ‘;’

    Reply
  3. JK says:
    April 26, 2021 at 8:43 am

    Utterly brilliant post that has finally helped me solve a problem that I’ve been trying to solve for hours. Thanks for helping everyone

    Reply
  4. Mike says:
    December 15, 2021 at 8:19 pm

    Thanks! This saved a few hours of head scratching today.

    Reply
  5. Shengqi Tao says:
    January 17, 2022 at 8:42 am

    Thanks! It works fine!

    Reply
  6. Rob P. says:
    August 31, 2022 at 1:54 am

    This was an unbelievable find. I had been searching for hours for a solution to this. We receive files from a vendor via FTP and we can’t process the data consistently because of the misc carriage returns in the files. I tried so many different methods, convert a CSV to Excel then back to CSV. Splitting the string into JSON, etc. etc. I just stumbled on this article and almost skimmed right past it because I couldn’t get the replace function to cooperate. I slowed down and read your solution and it worked PERFECTLY!!!!. Not only can I solve the issue with Power Automate, I can also solve it without needing to use any Premium features. Thanks so much for posting this.

    Reply
  7. Sunil Shenoy says:
    December 7, 2022 at 12:07 pm

    Thanks. This solved my issue…

    Reply
  8. Pato says:
    December 27, 2022 at 3:10 am

    Thank you so much. Like 6 hours into this and then, it fixes in 2 minutes.

    Regrets from Mexico.

    Reply
  9. Mike says:
    February 6, 2023 at 7:45 pm

    Do you know how to do a double break? Using this with the sharepoint https send of the following command adds an extra ” to the end that breaks the expression: “text”: “@{concat(variables(‘var_changesArray’),decodeUriComponent(‘%0A’),decodeUriComponent(‘%0A’))}”
    }

    Thanks!

    Reply
    1. Tom says:
      February 9, 2023 at 10:07 pm

      Hello Mike,
      try to put both the characters inside single decodeUriComponent(…)
      – decodeUriComponent(β€˜%0A%0A’)

      Reply
  10. Skweekah says:
    May 4, 2023 at 3:00 am

    Lifesaver!!! I was trying to replace newline with backslash n but to no avail. This fixed my issue in no time! Legend!

    Reply
  11. Joerg says:
    May 4, 2023 at 12:47 pm

    I spend days playing around to split and replace line breaks. Thanks to you I finally made it, nothing other I found did work.

    decodeUriComponent(‘%0A’)

    Is the key! Thanks a lot!

    Reply
  12. Ronaldo says:
    May 9, 2023 at 11:12 pm

    Data migration imported description field that is concatinated with multiple source fields with a SQL Char(13) . Now trying to generate a CSV file – format breaks because of line break. Applied all suggestions above and did not help. Am I missing anything?

    Reply
    1. Tom says:
      May 28, 2023 at 3:02 pm

      Hello Ronaldo,
      it’s hard to tell if you’re missing something without seeing the actual data.

      Reply
  13. Vinit says:
    June 20, 2023 at 8:05 pm

    Thanks a lot! I had been stuck on this for a while.

    Reply
  14. Alex V says:
    August 18, 2023 at 4:13 pm

    I want to send and email from a cell in excel, the text from the cell has new line characters but when I put it in the “send email” action it delete the new lines. I tried to compose an expression as you showed but still when it’s inside the “send email” action it deletes the new lines and send the email in just one line.

    Any ideas???

    Reply
    1. Tom says:
      September 7, 2023 at 12:21 pm

      Hello Alex,
      no ideas at this moment.

      Reply
  15. Nikolaos Zacharakis says:
    August 24, 2023 at 2:40 am

    Excellent article!!! I was also stuck and ignorant about this Power Automation limitation. Thank you very much πŸ™‚

    Reply
  16. Jen Grassan says:
    September 28, 2023 at 5:52 pm

    This is great for one line break, but I tried for multiple and couldn’t get to work. Thoughts?

    eg of String below. I want to leave the one break between Created comments, but remove the multiple line break to only one. I tried adding multiple here, but no luck.
    decodeUriComponent(β€˜%0A%0A%0A%0A%0A’)

    Created: 09-28-2023
    SH no expire – this won’t be removed
    nope
    nada

    Created: 09-28-2023
    SH Expire – This will be removed after test

    Created: 09-27-2023
    SH No Expiration – This will not expire.
    All good here.

    This is how I want it formatted:

    Created: 09-28-2023
    SH no expire – this won’t be removed
    nope
    nada

    Created: 09-28-2023
    SH Expire – This will be removed after test

    Created: 09-27-2023
    SH No Expiration – This will not expire.
    All good here.

    Reply
    1. Jen Grassan says:
      September 28, 2023 at 5:54 pm

      OK…it removed the line breaks in my comment. There are 5 in-between the second and third comment. Want to remove to make only 1.

      Reply
      1. Tom says:
        October 22, 2023 at 3:54 pm

        Hello Jen,
        that’s exactly how I’d do that, just repeat the character. If %0A doesn’t work I’d try %0D%0A

        Reply
  17. Pingback: Create An Excel File And Add Rows Using Power Automate
  18. Swathi says:
    December 13, 2023 at 9:46 am

    I struggled with line break issue in my expression, this helped me slove in seconds. Thank you.

    Reply
  19. Tracye says:
    February 27, 2024 at 6:06 pm

    If using the Html to text action, instead of replacing \n, \r, or using the %0A code you need to use and in a double replace function. You need to convert it to a first string because the action turns it into an object.
    Mine looks like this:
    replace(replace(string(items(‘Apply_to_each_Note’)?[‘notetext’]),”,”),”,’;’)

    Reply
  20. Tracye says:
    February 27, 2024 at 6:09 pm

    apologies, the div sections didn’t show up in the first reply – use an opening and closing div in your function

    Reply
    1. Tom says:
      March 17, 2024 at 1:25 pm

      Hello Tracye,
      thank you for sharing.

      Reply
  21. Pingback: How To Get Approval Comments In Power Automate
  22. Pingback: Add line break / new line for description field of Email – Dataverse / Power Automate – Nishant Rana's Weblog
  23. Meg L says:
    February 3, 2025 at 7:39 pm

    Thanks a ton for this post! Saved me loads of time. You are a star!

    Reply
  24. MikeD says:
    February 10, 2025 at 9:38 pm

    Thanks – This solved my problem!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

πŸš€ Master Power Automate

Join 2,100+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Still exchanging emails to get things approved?

Get the Approval Process solution and the Task Delegation App to skip the hard part and deploy an automated, fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundleβ€”everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes