You are viewing limited content. For full access, please sign in.

Question

Question

Anyone have a way to convert html characters to text in Workflow?

asked on December 7, 2023

I am down to the script activity which isn't the best fit since there are so many possible characters. Examples: "  and '

 

Thanks!

0 0

Answer

SELECTED ANSWER
replied on December 7, 2023

Chris,

If I understand your question correctly you are asking for a way to decode encoded HTML?  If so, you can decode any encoded text in the Script activity with a single line of code using the HTMLDecode method on the System.Net.WebUtility class.

Here is some sample code that takes an encoded text string from a token named EncodedHTML and correctly decodes it to a token named DecodedHTML.  The script correctly decodes both examples you cite.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Net

Namespace WorkflowActivity.Scripting.Script
    '''<summary>
    '''Provides one or more methods that can be run when the workflow scripting activity is performed.
    '''</summary>
    Public Class Script1
        Inherits ScriptClass90
        '''<summary>
        '''This method is run when the activity is performed.
        '''</summary>
        Protected Overrides Sub Execute()

            Me.SetTokenValue("DecodedHTML", System.Net.WebUtility.HtmlDecode(Me.GetTokenValue("EncodedHTML")))

        End Sub
    End Class
End Namespace

 

2 0
replied on December 8, 2023

Ha ha yeah I found this yesterday and it is just what I needed. Thanks for the reply!

https://stackoverflow.com/questions/122641/how-can-i-decode-html-characters-in-c

Note: you need to add 'using System.Net' or 'Import System.Net'(as shown above) in the top section of the scripting interface to be able to use 'DecodeHTML'.

I am pulling a block of text from another system (Synergy API) and it's converting special characters to HTML. This converts it all back to text data type. 

0 0

Replies

replied on December 8, 2023

This would be a great function to be added into Workflow since it already has encode functions.

2 0
You are not allowed to follow up in this post.

Sign in to reply to this post.