简体   繁体   中英

Apostrophe and reverse apostrophe in NSString

If I type '' (that is, the key directly to the left of the enter/return key 2x) in Helvetica Bold in Photoshop, I get the following:

在此处输入图片说明

However, if I draw this same string in iOS via NSString, I get:

在此处输入图片说明

Is there anyway to get the fancy apostrophes instead of the vertical line ones with an NSString?

In newer XCode, you can include the glyph directly in the @"" definition.

So: NSString *test = @"\‘Hello\’";

In older versions (and in more complex cases), you may find it helpful to use this format:

NSString *test = [NSString stringWithFormat:@"%CHello%C", 0x2018, 0x2019];

Check out Wikipedia for a reference to various quoting glyphs and the code points: http://en.wikipedia.org/wiki/Quotation_mark_glyphs

NSString *singleQuotes = @"\u2018\u2019";

When you want unicode characters its usually to display to the user so I use the NSLocalizedString function/macro

for example in code

NSString    * message = NSLocalizedString( @"some 'apostrophes'", @"" )

and then in the Localizable.strings file I map them to unicode string

"some 'apostrophes' " = "some ‘apostrophes’";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM