2

I want to display superscript 3 in console application. I've tried the following methods but none of them works.

Console.WriteLine("\xB3");

(from here)

Console.WriteLine("³"); // Copied from charmap.exe and also from Wikipedia

How can I display it?

Spidy776
  • 181
  • 1
  • 2
  • 10

2 Answers2

1

You need to make sure that the encoding of your console is appropriate for rendering the character that you are trying to output.

The relevant property is Console.OutputEncoding.

See MSDN: Console.OutputEncoding Property

0xB3 is a superscript 3 in Unicode, so you need to select UnicodeEncoding.

See MSDN: UnicodeEncoding Class

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
  • 1
    It is displaying fine for 2 but not for 3. `Console.WriteLine("{0}\xB2 = {1}", i, i * i);` is displaying **1² = 1 2² = 4** but `Console.WriteLine("{0}\xB3 = {1}", i, i * i * i);` is displaying **13 = 1 23 = 8** – Spidy776 Aug 07 '17 at 16:56
  • You might want to read this: https://stackoverflow.com/questions/32175482/what-is-the-difference-between-using-u-and-x-while-representing-character-lite – Mike Nakis Aug 07 '17 at 17:03
  • Take a look at this: https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts. for 4 and higher you need to use \u207 before your number. So, for 2^4 you would do: Console.WriteLine("2\u2074"); – Xcalibur37 Feb 26 '22 at 21:14
0

This works for me:

Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.Write("2\xB3");

Output:

D_W
  • 39
  • 5