iphone - 显示编码字符,如 å,ä,ö在UI标签中

发布于 2025-01-08 11:09:19 字数 118 浏览 6 评论 0原文

我有一个列表,其每一行都使用 UILabel。如果我尝试显示特殊字符,例如 å,ä,ö,它会将它们显示为 &aring &auml &ouml 如何将它们转换为 UTF8 编码的 NSString?

I have a list that uses UILabel for each of its rows. If I try to display special characters such as å,ä,ö, it displays them as å ä ö How do I convert them into a UTF8 encoded NSString?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远山浅 2025-01-15 11:09:19

这些字符在 WebView 中正确显示,因为它正确解释了 HTML 实体。

也许这个方便的 NSString 类别可以帮助您在 UILabel 中显示所需的文本:

https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/NSString+HTML.m

同时导入 NSString+HTML.h 和 NSString+HTML.m 文件,然后在你的课堂上使用

#import "NSString+HTML.h"

,然后你可以使用

NSString *decodedString = [encodedString stringByDecodingHTMLEntities];

编辑:

你也可以尝试HerbertHansen 在苹果开发板上的解决方案,不需要整个库

The characters display correctly in a WebView because the HTML entities are correctly interpreted by it.

Maybe this handy NSString category can help you to display the text how you want in a UILabel:

https://github.com/mwaterfall/MWFeedParser/blob/master/Classes/NSString+HTML.m

Import both NSString+HTML.h and NSString+HTML.m files, then in your class use

#import "NSString+HTML.h"

and then you can use

NSString *decodedString = [encodedString stringByDecodingHTMLEntities];

EDIT :

You can also try HerbertHansen's solution on the apple dev boards which doesn't need a whole library

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文