ios - 如何解码 swift 3 中的 unicode 字符?

标签 ios unicode utf-8 swift3 emoji

<分区>

我正在开发一个聊天应用程序,除此之外一切正常。此应用程序在 Android 和 iOS 平台上。我们想在聊天中传递表情符号。在 android 中,我们使用带有 StringEscapeUtils 的 UTF 编码。它在 android 中运行完美。当我们通过表情符号时enter image description here它被编码并存储在数据库中,如“\u263A”。

现在在 android 中,这个字符串也被解码并在 View 中完美显示,但有些我们无法在 iOS 中解码相同的字符串。我们只是尝试 使用 UTF 字符串解码。但它仍然不起作用。

我已经点击了这个链接 Print unicode character from variable (swift)

提前致谢。

最佳答案

最简单的方法是像下面这样使用 CFStringTransform。

let wI = NSMutableString( string: "\\u263a" )
CFStringTransform( wI, nil, "Any-Hex/Java" as NSString, true )
someUILabel.text = wI as String

关于ios - 如何解码 swift 3 中的 unicode 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41033024/

相关文章:

ios - ReactiveCocoa rac_valuesForKeyPath 在 Swift 中不起作用

IOS UIButton 不响应触摸,需要多次按下,UIScreenEdge 手势干扰?

iphone - UIViewController - UIModalPresentationCurrentContext 不旋转 presentingViewController

java - 动态迭代 unicode 字符

unicode - 如何在 GNAT 编程工作室中使用 unicode?

PHP iconv_strlen 问题

java - 字符串编码(UTF-8)JAVA

ios - NSUserTrackingDescription 失败

c# - 将字符串从 CP866 转换为 UTF8

unicode - 如果调用 chcp,则不会执行批处理脚本