ios - Get first character, symbol, number, or emoji at the start of NSString -
this question has answer here:
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
Post a Comment