3

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?

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
foebe
  • 359
  • 7
  • 17
  • Check out the Unicode tables here http://en.m.wikipedia.org/wiki/Wikipedia:Unicode_subscripts_and_superscripts – bweberapps Dec 22 '11 at 19:49

2 Answers2

7

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.

dreamlax
  • 93,976
  • 29
  • 161
  • 209
  • 3
    Note that in most typefaces in iOS, numbers 1,2 and 3 look different to the rest. See this question for more details (and a list of typefaces that are consistent):http://stackoverflow.com/questions/7663251/why-the-display-of-unicode-characters-for-superscripted-digits-are-not-at-the-sa/7663610#7663610 – jrturton Dec 22 '11 at 20:04
  • +1 @jrturton: Yes, I've noticed this in a number of fonts too. I suppose the alternative was for TUC to define `\u2070 ~ \u2079` as superscript digits that have `\u00B2`, `\u00B3`, and `\u00B9` as duplicates... but multiple codepoints for the same glyph is probably more ugly than logically sequential characters with non-sequential codepoints. – dreamlax Dec 22 '11 at 21:49
  • 1
    @BharatDodeja: There is no contiguous series for superscript letters in Unicode, they all belong to different regions and as such they may have a different "look" than others. Check [here](http://en.wikipedia.org/wiki/Wikipedia%3aUnicode_subscripts_and_superscripts#Superscripts_and_subscripts_block). – dreamlax Dec 16 '12 at 22:55
  • I tried the above super script code but code of 2 and 3 (\u00B2\u00B3\) is not working. Its displaying few special symbols on label. please let me know. – Mitesh Khatri Nov 19 '13 at 05:17
3

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⁰¹²³⁴⁵⁶⁷⁸⁹" 
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367