cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

Replace Newline in Flow Expression

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Advocate I
Advocate I

Re: Replace Newline in Flow Expression

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.

View solution in original post

13 REPLIES 13
Highlighted
Community Support
Community Support

Re: Replace Newline in Flow Expression

Hi @FlowNick,

 

Thanks for posting.

I will make some tests and share the results.

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Advocate I
Advocate I

Re: Replace Newline in Flow Expression

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.

View solution in original post

Highlighted
New Member

Re: Replace Newline in Flow Expression

Thanks FlowNick - workaround works perfectly!

Highlighted
Regular Visitor

Re: Replace Newline in Flow Expression

Saver of the day. this works awesome.

Highlighted
Advocate II
Advocate II

Re: Replace Newline in Flow Expression

I think I just found a different work around.  needed to replay new lines with <br> html tag.  I initalied a variable string.  In the string I hit enter so the only character in the string was a new line.  I then used the dynamic variable in the experssion.

Anonymous
Not applicable

Re: Replace Newline in Flow Expression

Hello,

 

I'm havin gsome trouble with the same. I'm trying to leverage the solution found but dont know what the "body('Html_to_text')" is referring to. Can someone explain that funciton? Thanks!

Highlighted
Advocate I
Advocate I

Re: Replace Newline in Flow Expression

Hi @Anonymous,

 

body('Html_to_text')

represents data converted through the Content Conversion connector (docs).

Highlighted
Anonymous
Not applicable

Re: Replace Newline in Flow Expression

Thanks for the reply Nick! i got it figured out.

Highlighted
New Member

Re: Replace Newline in Flow Expression

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

Highlighted
Resolver I
Resolver I

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?

 

 

Highlighted
Advocate I
Advocate I

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'), '')
Highlighted
Advocate V
Advocate V

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'), '')
Highlighted
Frequent Visitor

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

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Kudoed Authors
Users online (8,206)