Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
dhruv_mehta
Active Contributor
2,507
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
3 Comments
Labels in this area