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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -