ios - 获取 NSString 开头的第一个字符、符号、数字或表情符号

标签 ios objective-c unicode nsstring

<分区>

我只想获取 NSString 的第一个字符、符号、数字或表情符号。

由于表情符号被编码为 un​​icode 代理对,只需使用类似的方式获取第一个字符

str = [str substringToIndex:1];

将不起作用。

最佳答案

按照此处找到的答案: Simplest way to extract first Unicode codepoint of an NSString (outside the BMP)?

NSRange r = [myString rangeOfComposedCharacterSequenceAtIndex:0];
NSString *firstCharacter = [myString substringWithRange:r];

firstCharacter 为您提供 NSString 的第一个字符,无论它是如何编码的。

关于ios - 获取 NSString 开头的第一个字符、符号、数字或表情符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35045432/

相关文章:

ios - UITextView 文本指示器在错误的位置

iPhone数据传输问题

iphone - 用 "Done"按钮替换导航 Controller 上的右侧 UIBarButtonItem

java - 在 Mac 上打印到点阵打印机

Java:如何检查字符是否属于特定的unicode block ?

ios - Flutter构建ios错误: Encountered error while building for device

iphone - UITableViewRowAnimationFade 不工作

javascript - 使用 fast-csv 模块转换文件 utf8

iphone - NSTimer 委托(delegate)选择

unicode - 英特尔C编译器和L”前缀