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?
Solved! Go to Solution.
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.
Hi @FlowNick,
Thanks for posting.
I will make some tests and share the results.
Regards,
Michael
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.
Thanks FlowNick - workaround works perfectly!
Saver of the day. this works awesome.
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.
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!
Hi @Anonymous,
body('Html_to_text')
represents data converted through the Content Conversion connector (docs).
Thanks for the reply Nick! i got it figured out.
It works!! You saved me a lot of time and I'm really thankful
@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
@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?
Thanks @Megasween thanks works perfect. A recap for others:
I tried reversing the solution - using decodeUriComponent to get the newline for the split. Works as well.
replace(body('Html_to_text'), decodeUriComponent('%0A'), '')
use concat and {" \n\n"} ... yes with double quotes
example >>> concat('string 1',{" \n\n"},'String 2')
This will output
string1
string2
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!
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!
User | Count |
---|---|
100 | |
37 | |
26 | |
23 | |
16 |
User | Count |
---|---|
132 | |
52 | |
48 | |
36 | |
24 |