如何将Unicode字符串(\\\â,等)转换为NSString显示? [英] How to convert Unicode strings (\u00e2, etc) into NSString for display?

查看:198
本文介绍了如何将Unicode字符串(\\\â,等)转换为NSString显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图支持来自各种国际用户的任意unicode。他们已经在他们的iPhone上的sqlite数据库中放了一大堆数据,现在我想把数据捕获到一个数据库,然后发送回他们的设备。现在我正在使用一个php页面,它从互联网mysql数据库发送数据。数据正确保存在mysql数据库中,但是当它返回时,它以unicode文本形式出现,例如

I am trying to support arbitrary unicode from a variety of international users. They have already put a bunch of data into sqlite databases on their iPhones, and now I want to capture the data into a database, then send it back to their device. Right now I am using a php page that is sending data back to from an internet mysql database. The data is saved in the mysql database properly, but when it's sent back it comes out as unicode text, such as


Frank \\\â \\\€\\\™s iPad

Frank\u00e2\u0080\u0099s iPad

而不只是


Frank's iPad

Frank's iPad

其中撇号应该是一个卷曲撇号。

where the apostrophe should really be a curly apostrophe.

发布到另一个问题的答案表示没有内置的Cocoa方法将unicode字符串的\\\â\\\€\\\™部分从Web服务器转换为NSString对象。这是正确的吗?

The answer posted to another question indicates that there is no built-in Cocoa methods to convert the "\u00e2\u0080\u0099" portion of the unicode string from the webserver to an NSString object. Is this correct?

这似乎真的令人惊讶(和令人惊讶的是,令人失望的),因为Cocoa绝对允许输入来自许多不同的Unicode字符,我需要支持任何任意语言,从来没有听说过,和所有可能的字符。我把它们保存到本地的sqlite数据库并且从本地的sqlite数据库保存好了,但是一旦我把它发送到一个web服务器,然后可能下拉不同的数据,我想确保从web服务器提取的数据格式正确。

That seems really surprising (and scarily disappointing), since Cocoa definitely allows input from many different Unicode characters, and I need to support any arbitrary language that I have never heard of, and all of the possible characters. I save them to and from the local sqlite database just fine now, but once I send it to a web server, then perhaps pull down different data, I want to ensure the data pulled from the web server is correctly formatted.

推荐答案


[...]没有内置的Cocoa方法来转换[...]。这是
吗?

[...] there is no built-in Cocoa methods to convert [...]. Is this correct?

这不正确。

您可能对 CFStringTransform 感兴趣,它的功能。这是一个完全成熟的ICU转换引擎,可以(也)执行您所要求的转换。

You might be interested in CFStringTransform and it's capabilities. It is a full blown ICU transformation engine, which can (also) perform your requested transformation.

请参阅使用目标C / Cocoa解除unicode unicode字符,即\\\ሴ

这篇关于如何将Unicode字符串(\\\â,等)转换为NSString显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆