4

How do I show a to the power 2 in the string.format?

analysis = String.Format("\nFormula: a^2 + b^2 = c^2");

Instead of a^2, I would like to show the same way as shown on the HTML page.

<strong>Formula: a<sup>2</sup> + b<sup>2</sup> = c<sup>2</sup></strong> 
Amit
  • 129
  • 10

1 Answers1

2

String.Format doesn't support converting characters to superscript. You'll need to find the correct characters yourself and pass those to String.Format.

See this answer for ways to do that.

Pepper Paige
  • 117
  • 8
  • 1
    Got it. Thanks for your help. Here is the code analysis = String.Format("Formula: a" + "\xB2" + "+ b" + "\xB2" + " = c" + "\xB2"); – Amit Aug 11 '18 at 20:51