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 -

python - GitPython: check if git is available -

php - Extract Text from HTTP referer -