I have one string which needs to change with Superscript

string str="ABC#"; I want add replace superscript with #. please suggest

Let me Explain with Example Suppose I enetered a string **My Name is#

My# name is**

My output needs to be same as in screenshots,means i want # to be superscript in string. enter image description here

Just wanted to know how to do it in Apex code

  • 2
    Hi. The question is not at all clear. Please edit the question to clarify what you mean. Is it that you want to strip an alpha string from the start of a string that includes a # character, or alpha characyers before a numeric, or something completely different? – Phil W Jan 13 '20 at 8:37
  • i updated the question. – ajay bagdad Jan 13 '20 at 9:25
  • This still is not clear. Please try to elaborate further. – Phil W Jan 13 '20 at 11:01

You can't display superscript in Apex code itself. If you want to display it elsewhere then you can use the sup HTML tag. This should display your # in superscript in rich text fields, HTML emails, and websites. Since normal text fields in Salesforce don't support HTML tags, you won't be able to use it there. Adding the tags is relatively easy:

String str = 'ABC#';
str = str.replaceAll('#', '<sup>#</sup>');

I hope that helps, if not, please clarify your question further.

PS: rich text fields don't support all HTML tags, here's a list of supported tags.

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.