Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
mahitham
Creator II
Creator II

How to remove special character from a field

Hi,

Can any one please help me on below requirement.

I have a Description field like below.But it contains some HTML  special characters.

Please help me to remove those HTML  special characters and Please help me to get the below Expected Description field

Description

<p>A code that identified  by it's financial type.</p>
<span>The date was no longer be used.</span>
<p>A <span>Drive to identifies a customer.</span></p>
<p><span style="font-size: 12.0px;">The Number of subsidiaries recorded.</span></p>

 

Expected Description

A code that identified  by it's financial type.

The date was no longer be used.

A Drive to identifies a customer.

The Number of subsidiaries recorded.

 

Thanks in advance

 

 

 

4 Replies
naumanshah
Contributor III
Contributor III

You'll need to implement a function which can parse the input strings for stripping html tags.

Have a look at following:

https://community.qlik.com/t5/QlikView-Documents/Function-to-strip-HTML-codes-from-a-field-during-lo...

 

tommyl
Creator
Creator

mahitham
Creator II
Creator II
Author

Hi @naumanshah 

Thanks for your reply.

I am not able to understand how to use below function .

Function stripHTML(strHTML)
   Dim objRegExp, strOutput
  Set objRegExp = New Regexp
  objRegExp.IgnoreCase = True
  objRegExp.Global = True
  objRegExp.Pattern = "(?:<style.+?>.+?</style>|<script.+?>.+?</script>|<(?:!|/?[a-zA-Z]+).*?/?>)"
  'Replace all HTML tag matches with the empty string
  strOutput = objRegExp.Replace(strHTML, "")
  stripHTML = strOutput 'Return the value of strOutput
  Set objRegExp = Nothing
End Function
 
Can you please explain in my scenario.
My script is like below
LOAD
ID,
Name,
Description
FROM [$(vG.LoadPath)Description.QVD]
(qvd);
vunguyenq89
Creator III
Creator III

Hi,

One way is to loop through each row and remove all pieces of text wrapped between '<' and '>' . See the sample script below:

// Load original data
Description_Temp:
LOAD ID, Name, Description
FROM [$(vG.LoadPath)Description.qvd] (qvd);

Description:
Load * INLINE [ID, Description_Clean];

//Loop through each row in the qvd file
For i=0 to NoOfRows('Description_Temp')-1
	Let vID = Peek('ID', $(i),'Description_Temp');
	Let vDescription = Peek('Description', $(i),'Description_Temp');
	vTagCount = SubStringCount('$(vDescription)','<');
	// Identify and remove text between <...> until no <tag> left
	Do While vTagCount>0
		vTag = '<' & TextBetween('$(vDescription)','<','>',1) & '>';
		vDescription = Replace('$(vDescription)','$(vTag)','');
		vTagCount = SubStringCount('$(vDescription)','<');
	Loop;
	Load * INLINE [
		ID, Description_Clean
		"$(vID)","$(vDescription)"](txt, msq);
Next i;

Left Join(Description) LOAD ID, Name Resident Description_Temp;
		
DROP TABLE Description_Temp;

Hope this helps!

BR,

Vu Nguyen