'How to write superscript in a string and display using MessageBox.Show()?

I am trying to output the area using a message box, and it should be displayed as, for example, 256 unit^2...

How can I write a superscript (for powers) and a subscript (like O2 for oxygen)???

This guy here adds a superscript like (TM):

Adding a TM superScript to a string

I Hope I got myself clear! Thanks in advance and sorry for any inconvenience...



Solution 1:[1]

Here's superscripts and subscripts

wikipedia

And here's how to escape unicode characters in c#

MSDN

Solution 2:[2]

I've used this extension for superscript.

    public static string ToSuperScript(this int number)
    {
        if (number == 0 ||
            number == 1)
            return "";

        const string SuperscriptDigits =
            "\u2070\u00b9\u00b2\u00b3\u2074\u2075\u2076\u2077\u2078\u2079";

        string Superscript = "";

        if (number < 0)
        {
            //Adds superscript minus
            Superscript = ((char)0x207B).ToString();
            number *= -1;
        }


        Superscript += new string(number.ToString()
                                        .Select(x => SuperscriptDigits[x - '0'])
                                        .ToArray()
                                  );

        return Superscript;
    }

Call it as

string SuperScript = 500.ToSuperScript();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 podiluska
Solution 2 Mobz