Recognize special characters in NSString

老子叫甜甜 提交于 2019-12-06 12:49:25

Characters outside of the "basic multilingual plane" - in other words, characters whose Unicode value is greater than U+FFFF - are stored in NSString as two UTF-16 characters, a so-called surrogate pair.

For example, "👌" = U+1F44C (OK HAND SIGN) is stored in NSString as the two characters U+D83D, U+DC4C.

To correctly split a string with surrogate pairs, use the

enumerateSubstringsInRange:options:usingBlock:

method of NSString with the NSStringEnumerationByComposedCharacterSequences option.

Another useful method is rangeOfComposedCharacterSequenceAtIndex: to determine the range of a composed character sequence at a certain position.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!