【iOS】iOS OC截取字符串时emoji表情处理 取emoji表情的range

做了一个类似于浏览器标签的功能,取出主色调,选取标题第一个字,这里标题是可以编辑的,遇到表情符号就出现了以下状况:
image.png

很尴尬对不对。

Stack Overflow了一下,代码如下:

    nsssting *string = @"����������";
    NSRange range = [string   rangeOfComposedCharacterSequencesForRange:NSMakeRange(0, 1)];
    NSString * result = [string substringWithRange:range];

这里用到了rangeOfComposedCharacterSequencesForRange方法,把解释翻译一下:

Returns the range in the string of the composed character sequences for a given range.
This method provides a convenient way to grow a range to include all composed character sequences it overlaps.
返回给定范围内组合字符序列的字符串范围。此方法提供了一种方便的方法来扩展,使其包含所有与其重叠的字符序列。
@parameters  range
             A range in the receiver. The range must not exceed the bounds of the receiver.
接收机中的一个量程。范围不得超过接收机的范围。
@parameters  return
             The range in the receiver that includes the composed character sequences in range.
接收机中包括组合字符序列的范围

效果如下:
image.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值