0

I have rich text field . I want remove font weight style from that.

Eg:

"<p>Salesforce Technoligy</p><br><p><b>Releases:</b></p><ul><li><b style="font-weight: 32px;">Please stay tuned</b></li></ul><ul><li><b style="font-size: 12px;font-weight: 22px;">Click here</b></li></ul>"

I want remove all the font weight tags like below in apex

"<p>Salesforce Technoligy</p><br><p><b>Releases:</b></p><ul><li>b>Please stay tuned</b></li></ul><ul><li><b style="font-size: 12px">Click here</b>/li></ul>"

I have tried

String removetag = '<p>Salesforce Technoligy</p><br><p><b>Releases:</b></p>ul><li><b style="font-weight: 32px;">Please stay tuned</b></li></ul><ul>li><b style="font-size: 12px;font-weight: 22px;">Click here</b></li>/ul>'
removetag = removetag.remove(removetag.subStringBetween('font-weight:','"'));
removetag = removetag.replaceAll('font-weight:','');

My font weight will be changed dynamically But style is empty. Anyone can help with this

1 Answer 1

1

Try the replace function.

String removetag = '<p>Salesforce Technoligy</p><br><p><b>Releases:</b></p>ul><li><b style="font-weight: 32px;">Please stay tuned</b></li></ul><ul>li><b style="font-size: 12px;font-weight: 22px;">Click here</b></li>/ul>';
removetag = removetag.replaceAll('font-weight: \\d*px;', '').remove('style=""');
3
  • 1
    my font weight is dynamic
    – sfdc1100
    Jul 20, 2021 at 6:31
  • i've updated my answer
    – Damecek
    Jul 20, 2021 at 7:15
  • 1
    Thanks! It worked
    – sfdc1100
    Jul 20, 2021 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.