Skip to Content
Technical Articles

SAP C4C ABSL : Convert Rich text to Plain Text . Remove all HTML tags from the text.

Dear All,

We know we can create KUT field of Type Formatted text, however sometimes we need the Plain Text from those Rich text field.

Scenarion : We needed to send the plain text from Rich Text to a third party WS ( Was a very old legacy system unable to parse HTML Tags).

Solution :

Created a Reuse Lib and Resue function : ( This wil be helpful to keep this kind of codes to be reused)

My Reuse function had one Import : String ( formatted text ) and a String as return ( plain Text).

Code :

import ABSL;
import AP.PDI.bo;

var result : DataType::String;
var stringTo = FORMATTEDTEXT;

if(!stringTo.IsInitial()){
	var strinWithoutTags = stringTo.ReplaceRegex("<[^>]*>","");
	result = strinWithoutTags;
	if( strinWithoutTags.Contains("&nbsp")){
		var final = strinWithoutTags.ReplaceRegex("&nbsp;","");
		result = final;
	}
}

return result;

 

So the Regex : “<[^>]*>”,””  , removed all the Tags and replaces them with “” .

Regex “&nbsp;”,””, removes all the &nsp; space.

You can play around with Regex with a website :

https://regexr.com/

I hope this helps a lot of deveopers to play around with Regex and a quick way to remove all the nasty html/ Rich text tags.

 

BR

Dhruvin

2 Comments
You must be Logged on to comment or reply to a post.