iphone - display encoded characters like å,ä,ö in UILabel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 10:32:27

问题


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 &aring &auml &ouml How do I convert them into a UTF8 encoded NSString?


回答1:


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



来源:https://stackoverflow.com/questions/9416237/iphone-display-encoded-characters-like-%c3%a5-%c3%a4-%c3%b6-in-uilabel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!