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: 
Not applicable

Remove rtf tags but keep newlines

I have a field that is imported in rtf format and the tags are stripped away during the load, leaving just the plain text.

I'm finding difficulty keeping the new lines in this situation. Is it possible to have a fiel entry with new line character?

I've tried replacing \par with chr(13) and evaluating it, also replacing \par with ' & chr(13) & '

Any ideas/experience with this?

Thanks

1 Reply
Not applicable
Author

Hi All,

I am beginner with QlikView and I had to face a challenge of extracting the plain text by parsing  RTF/RichText. Seems to be an easy problem and the solution is even easier ,but it took me some time to arrive at the solution, hence i would like to share it with the community. 

I created a custom function in QlikView  by writing a JScript  in the Edit Module (CTRL +M) space. The function is as shown below

function convertToPlain(rtf)

{

    rtf = rtf.replace(/\\par?/g, "");

    return rtf.replace(/\{\\[^{}]+;\}|[{}]|\\\n?[A-Za-z]+\n?(?:-?\d+)?[ ]?|[{\\\*}]/g, "");

}

All this function does is replaces the string which matches the regex expression marked in bold with a empty string  "" . I am sure that some of you can write a better Regex Expression, but this was the one which worked for me(there are lot of posts where you find different regex expression which might work for you but you need to do thorough testing). You can use websites such as https://regex101.com/‌ to build your own Regex Exp and test it.

Now all  you have to do is to call this function in your load script as shown below

Load  convertToPlain(<YourRTFColumn>) from <YourSource>;

Please feel free to contribute if you think there is a better way to do it or someone wants to add on to this.