Solved

How to remove &nbsp

  • 28 August 2023
  • 4 replies
  • 202 views

Badge +2
  • Contributor
  • 8 replies

Hello,

I am extracting certain items from an email that comes into FreshService with this experssion:

substring('{{ticket.description | strip_html}}', indexOf('{{ticket.description | strip_html}}', 'Department:',0)+length('Department:'), indexOf('{{ticket.description | strip_html}}', 'Division:', indexOf('{{ticket.description | strip_html}}', 'Department:',0)) )

 

It is all working as intended - however, the output gives spaces at the end, in the form of:

 

 Delivery 

 

Does anyone have any insight into how to remove the &nbsp from the result?

icon

Best answer by vdb 28 August 2023, 19:08

View original

4 replies

Userlevel 6
Badge +11

Hi.

Is it possible that your emails contains such spaces?

Have you tried subtracting 1 to the length and see the result?

Also, liquid filters might help. Please check handling whitespaces:

Whitespace control – Liquid template language (shopify.github.io)

 

Hope this helps.

 

Regards,

To remove the   (non-breaking space) from the output of your expression, you can use additional string manipulation functions to clean up the result. It looks like you're using some sort of template language or scripting environment to process the email content. Assuming you have access to basic string functions, you can add another step to replace   with an empty string.

Here's an example of how you can modify your expression to achieve this:

replace( substring( '{{ticket.description | strip_html}}', indexOf('{{ticket.description | strip_html}}', 'Department:', 0) + length('Department:'), indexOf('{{ticket.description | strip_html}}', 'Division:', indexOf('{{ticket.description | strip_html}}', 'Department:', 0)) ), ' ', '' )

In this modified expression, the replace function is used to replace all occurrences of   with an empty string, effectively removing the non-breaking spaces from the output. Make sure to integrate this adjusted expression into your workflow where you're processing the email content in FreshService.

 

 

 

Badge +2

Hi.

Is it possible that your emails contains such spaces?

Have you tried subtracting 1 to the length and see the result?

Also, liquid filters might help. Please check handling whitespaces:

Whitespace control – Liquid template language (shopify.github.io)

 

Hope this helps.

 

Regards,

 

It is coming out of an HRIS system, so editing on that end is near impossible. I’ve tried liquid filters in a few different ways with no success. Anytime I place &nbsp in the freshservice automator as something to replace, it just replaces it with actual space.

 

subtracting 1 on the length is giving me the same result. 

Badge +2

To remove the   (non-breaking space) from the output of your expression, you can use additional string manipulation functions to clean up the result. It looks like you're using some sort of template language or scripting environment to process the email content. Assuming you have access to basic string functions, you can add another step to replace   with an empty string.

Here's an example of how you can modify your expression to achieve this:

replace( substring( '{{ticket.description | strip_html}}', indexOf('{{ticket.description | strip_html}}', 'Department:', 0) + length('Department:'), indexOf('{{ticket.description | strip_html}}', 'Division:', indexOf('{{ticket.description | strip_html}}', 'Department:', 0)) ), ' ', '' )

In this modified expression, the replace function is used to replace all occurrences of   with an empty string, effectively removing the non-breaking spaces from the output. Make sure to integrate this adjusted expression into your workflow where you're processing the email content in FreshService.

 

 

 

This seems to be working for me. I was trying to do the same thing with the Output of this expression node and it would just convert the &nbsp to whitespace. Going to vet it out a bit and make sure. Thank you

Reply