cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
FlowNick
Level: Powered On

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
FlowNick
Level: Powered On

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

10 REPLIES 10
Community Support Team
Community Support Team

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.
FlowNick
Level: Powered On

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

alexander7567
Level: Powered On

Re: Replace Newline in Flow Expression

Thanks FlowNick - workaround works perfectly!

Highlighted
shahidsaud
Level: Powered On

Re: Replace Newline in Flow Expression

Saver of the day. this works awesome.

Megasween
Level: Powered On

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!

FlowNick
Level: Powered On

Re: Replace Newline in Flow Expression

Hi @Anonymous,

 

body('Html_to_text')

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

Anonymous
Not applicable

Re: Replace Newline in Flow Expression

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

TitoValle
Level: Power Up

Re: Replace Newline in Flow Expression

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

stephenJames
Level 8

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?

 

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 302 members 6,266 guests
Please welcome our newest community members: