views:

60

answers:

1

For example, suppose I have an NSString @"20O(2H,1H)19O", and I want all the numbers to be superscript. Is there an easy way to do this?

+4  A: 

I think you probably want NSAttributedString with NSSuperScriptAttributeName. If you need to keep it in an NSString, unicode has characters for superscripted digits.

Carl Norum
UPDATE: I ended up using an NSMutableAttributedString. Apple's documentations is quite wanting, though, so I didn't get much out of it. I ended up following the examples in Aaron Hillegass's "Cocoa Programming For Mac OS X". It was actually quite a chore, as I had to keep track of the exact character positions of the bits that I wanted to superscript. Details of what I did can be found in the source code for AppController.m, in the method generateFormattedReactionString, from my project at http://code.google.com/p/mac-helios-sim/, in case anyone is curious.
TraxusIV