- (NSRange)rangeOfComposedCharacterSequencesForRange:(NSRange)range;
- (NSRange)rangeOfComposedCharacterSequenceAtIndex:(NSUInteger)index;
这两个方法主要针对一些特殊字符获取真正的范围,防止你把同一个字符给拆开了,比如👴🏻👮🏽这种字符,它们并不是只占一个字符
NSString *string = @"👴🏻👮🏽哈哈哈";
NSRange range = [string rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, 5)];
NSRange range2 = [string rangeOfComposedCharacterSequenceAtIndex:5];
NSLog(@"string length : %zd range :%@ range 2: %@", string.length, NSStringFromRange(range), NSStringFromRange(range2));
输出结果:
2017-08-31 10:31:06.642 thread[6851:1320629] string length : 11 range :{0, 8} range 2: {4, 4}
看例子应该很容易看明白。