ios - Get first character, symbol, number, or emoji at the start of NSString -


i first character, symbol, number, or emoji of nsstring.

since emojis encoded unicode surrogate pairs, getting first character using like

str = [str substringtoindex:1]; 

will not work.

following answer found here: simplest way extract first unicode codepoint of nsstring (outside bmp)?

nsrange r = [mystring rangeofcomposedcharactersequenceatindex:0]; nsstring *firstcharacter = [mystring substringwithrange:r]; 

firstcharacter gives first character of nsstring no matter how it's encoded.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -