Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
crichter14
Creator II
Creator II

Removing JSON(HTML?) code from a String

I hope I'm not posting this twice (sorry) I can't find that I hit send.  So working with a nightmare file and our partner wrote a script, not in QS - but it looks like HTML (maybe?) that returns some string fields with a few extra characters.  They look like HTML (like <b> and </b> for bold).

Anyways there's a line that uses the replace comment and it's not working.  

I've tried changing the ampersand (&) and the semi-colon (;) to their ASCII and that does nothing.  I can't use purgechar because I still need the letters (n,b,s,p and b).  Suggestions for this new-ish Qlik Cloud user?

Here's the line of Code: 

Replace(Replace(Replace([Answer Name], '&nbsp;',' '),'<b>',''),'</b>','') AS [Answer Name]

 

Suggestions welcome and thank you in advance!

Labels (2)
1 Reply
weesr
Contributor
Contributor

To remove HTML tags from a string in Qlik Cloud, your approach using the Replace function is correct, but it might need some adjustments depending on the tags you're encountering. The Replace function works by sequentially replacing one string with another, so chaining multiple Replace calls is a valid way to strip out multiple unwanted elements.

Here's a step-by-step breakdown and a refined approach: check innovative CBD

  1. Nested Replace Functions: You're already using nested Replace functions, which is good. However, ensure that all potential HTML tags are accounted for. For example, if there are other tags like <i>, <u>, etc., you would need to include them in the sequence.

  2. Handling Other HTML Entities: If there are other HTML entities (like &nbsp;), ensure they are all addressed. If you have multiple entities, you can keep chaining Replace functions.

  3. Alternative Approach with PurgeChar: If you're dealing only with specific HTML tags and no other special characters, PurgeChar can help remove specific unwanted characters or patterns without removing the characters you want to keep.

Here’s your code with a more comprehensive approach:

Replace(
Replace(
Replace(
Replace([Answer Name], '&nbsp;', ' '),
'<b>', ''
),
'</b>', ''
),
'<i>', ''
) AS

You can keep adding Replace functions as needed for other tags.