foebe
foebe

Reputation: 359

Superscripting any Letter/Number

Is there actually any way to superscript any number? In my App I need to superscript the numbers from 0 to 24.
I know that with \u2070 for example I can display a superscripted 0, but in Unicode there aren't all the numbers I need.
I just want to set a NSString to a number with an exponent, like 10^24. Is there any way to do this?

Upvotes: 3

Views: 4150

Answers (2)

dreamlax
dreamlax

Reputation: 95335

They are scattered throughout the Unicode blocks:

  • \u2070 is superscript 0
  • \u00B9 is superscript 1
  • \u00B2 is superscript 2
  • \u00B3 is superscript 3
  • \u2074 is superscript 4
  • \u2075 is superscript 5
  • \u2076 is superscript 6
  • \u2077 is superscript 7
  • \u2078 is superscript 8
  • \u2079 is superscript 9

To put them altogether and make it easier to choose the digit, you can either use a wchar_t[] type, or store them in a string:

NSString *superDigits = @"\u2070\u00B9\u00B2\u00B3\u2074\u2075\u2076\u2077\u2078\u2079";

As an exercise you could create a method that formats an integer as a superscript string.

Upvotes: 7

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230336

Well, there are all the numbers you need. Look here

Example:

ruby-1.9.3 > "1\u2070\u00B9\u00B2\u00B3\u2074\u2075\u2076\u2077\u2078\u2079"
 => "1⁰¹²³⁴⁵⁶⁷⁸⁹" 

Upvotes: 3

Related Questions