Skip to main content

Notifications

Community site session details
Power Automate - Building Flows
Answered

Replace Newline in Flow Expression

Like (4) ShareShare
ReportReport
Posted on 20 Sep 2017 00:55:48 by 111

I have a flow that is parsing a plain text email and creating an item in a SharePoint list.

 

Everything works great except for when a user enters data with a newline or carriage return (which I don't want in the SP list). I can not figure out how to replace a new line (\n) or any other non-printable character.

 

I have tried the obvious...

 

replace(body('Html_to_text'), '\n', '')

I have tried what others claim to be the only solution...

 

replace(body('Html_to_text'), '
', '')

As well as several other options (e.g.; character codes)...

 

replace(body('Html_to_text'), Char(13), '')

And nothing works (even when the run doesn't generate an error, the new lines are not replaced). I am able to replace printable characters without issue, it's just the non-printable characters.

 

So, am I missing something or is it impossible to do what I'm trying to do?

  • Suggested answer
    Foxman Profile Picture
    3 on 04 Dec 2024 at 18:07:44
    Replace Newline in Flow Expression
    You can initialize a string variable and just put a line break for the initial value. Then use the variable as your search text in the replace function. 
     
     
  • MWals Profile Picture
    2 on 19 Apr 2024 at 20:03:38
    Re: Replace Newline in Flow Expression

    In my case I needed to replace \r\n so it was 

    %0D%0A
  • PraveenMdl Profile Picture
    2 on 05 May 2023 at 07:39:54
    Re: Replace Newline in Flow Expression

    Hi,

     

    I am trying to export a SharePoint list into a CSV file. One of the columns has got \n (linefeed) and it is causing the breaking of the rows.

     

    I tried to use the following expression in compose before creating csv file

    uriComponentToString(replace(uriComponent(body('select')), '%0A', ''))

    I am getting following error, can someone direct me to right place or help .. thank you.

     

    PraveenMdl_2-1683272260682.png

     

     

     

     

  • racherpeg_859 Profile Picture
    3 on 21 Jan 2022 at 23:45:47
    Re: Replace Newline in Flow Expression

    I've been working on this for weeks! Converting an HTML table into a Sharepoint list item then to email.  This was the piece I couldn't fix.  It works great!

  • KaiTang Profile Picture
    5 on 09 Apr 2021 at 16:17:42
    Re: Replace Newline in Flow Expression

    That is great, I have been trying to fix the seemingly random addition of non printable characters for ages.  Agree it isn't pretty but definitely did the job.  Thanks FlowNick!

  • manvinder277 Profile Picture
    21 on 01 Jun 2020 at 18:07:54
    Re: Replace Newline in Flow Expression

    use concat and {" \n\n"} ... yes with double quotes

    example >>> concat('string 1',{" \n\n"},'String 2')

     

    This will output

    string1

    string2

  • degvalentine Profile Picture
    193 on 01 May 2020 at 22:33:13
    Re: Replace Newline in Flow Expression

    I tried reversing the solution - using decodeUriComponent to get the newline for the split. Works as well.

     

    replace(body('Html_to_text'), decodeUriComponent('%0A'), '')
  • DennisKuhn1 Profile Picture
    33 on 19 Jan 2020 at 23:33:02
    Re: Replace Newline in Flow Expression

    Thanks @Megasween  thanks works perfect. A recap for others:

    1. Initialize a variable of type string, e.g. named NewLine
      1. In the Value field hit Enter, you should see the field growing vertical
    2. Use replace( 'your text with newlines in it', variables('NewLine'), '')
  • stephenJames Profile Picture
    286 on 17 Jul 2019 at 18:31:28
    Re: Replace Newline in Flow Expression

    @FlowNick wrote:

    Thanks Michael.

     

    Here's what I'm currently using as a workaround:

     

    uriComponentToString(replace(uriComponent(body('Html_to_text')), '%0A', ''))

    I figured, since I can replace printable characters, I'd just temporarily convert the string to all printable characters, replace them, then convert it back. It's hack-ish and inefficient but working.

     

    I look forward to seeing your results.


    I hate to Necro, so sorry in advance. 

     

    I am using a similar bit of code to remove line breaks and apostrophes.

    uriComponentToString(replace(replace(uriComponent(body('Html_to_text')), '%0A', ''), '%27',''))

    This works to put evrything on a single line and removes the characters i dont need. However i cannot seem to get my substrings to run as i keep getting the following message

    flowerror.PNG

     

    @FlowNick mentioned that he " temporarily convert the string to all printable characters, replace them, then convert it back." . Is there a step to convert it back that i am missing?

     

     

  • TitoValle Profile Picture
    3 on 19 Apr 2018 at 05:09:52
    Re: Replace Newline in Flow Expression

    It works!! You saved me a lot of time and I'm really thankful  Cat Happy

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,743 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,079 Most Valuable Professional

Leaderboard
Loading started
Loading started
Loading complete