Reputation: 1684
I need to make chemistry formulas (SO4^2-), and the easiest way to make subscripts and superscripts seems to be adding UTF-8 characters, since KCTSuperscriptAttributeName:
property of NSAttributedString doesn't work.
Is it possible for me to make an nsstring with normal characters and utf-8 characters?
Thanks
Upvotes: 3
Views: 2823
Reputation: 89509
Justin's answer is good but I think what you might really be looking for is NSAttributedString
(documentation linked for you) or NSMutableAttributedString
, where you can add superscripts, subscripts, and other character styles that NSString
by itself can't handle.
Take a look at other NSAttributedString
questions here or via Google, like this potentially related question or this one.
Hope this helps you out!
Upvotes: 4
Reputation: 753
According to NSString Reference "NSString is implemented to represent an array of Unicode characters, in other words, a text string."
It would be convenient to write as below: NSString* myStr = @"Any Unicode Character You Want";
Just make sure that your default text encoding is unicode.
Upvotes: 4
Reputation: 104698
yes. i assume you know the normal approach to make an NSString
- here's one method to create an NSString
from a utf8 string: -[NSString initWithUTF8String:]
.
Upvotes: 3