how to get first three characters of an NSString?

后端 未结 3 623
旧巷少年郎
旧巷少年郎 2020-12-07 19:57

How can I return the first three characters of an NSString?

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 20:25

    the right way is:

    text = [text substringToIndex:NSMaxRange([text rangeOfComposedCharacterSequenceAtIndex:2])];
    

    substringToIndex of NSString is indexing by code unit, emoji takes two code units.

    make sure check the index yourself.

提交回复
热议问题