1

我有一个我需要解码的例子:

@"für"

我怎样才能把它解码成一个 NSString 所以它看起来像

毛皮

我尝试了很多东西,包括

[@"f&#252r" stringByDecodingHTMLEntities] > f&#252r  
[@"f&#252r" gtm_stringByUnescapingFromHTML] > f&#252r  

但没有运气。

谢谢!

更新基于 vikingosegundo 的解决方案

    NSLog(@"möchte decoded to :     > %@", [@"möchte" stringByEncodingHTMLEntities] );
    NSLog(@"möchte decoded to: > %@", [@"möchte" stringByDecodingHTMLEntities] );

    NSLog(@"für decoded to :     > %@", [@"für" stringByEncodingHTMLEntities] );
    NSLog(@"für decoded to: > %@", [@"für" stringByDecodingHTMLEntities] );

    NSLog(@"m&#246chte decoded:%@", [@"m&#246chte" stringByDecodingHTMLEntitiesComma] );
    NSLog(@"f&#252r decoded:%@", [@"f&#252r" stringByDecodingHTMLEntitiesComma] );

möchte decoded to :     > möchte
möchte decoded to: > möchte
für decoded to :     > für
für decoded to: > für
m&#246chte decoded:möchte
f&#252r decoded:für

注意:stringByEncodingHTMLEntities 来自https://github.com/mwaterfall/MWFeedParser/tree/master/Classes stringByDecodingHTMLEntitiesComma 来自 vikingosegundo 的类别。

4

1 回答 1

0

尝试

[@"für" stringByDecodingHTMLEntities];

或者

[@"für" gtm_stringByUnescapingFromHTML];

(注意;

此类别也适用于缺少的;.

于 2012-06-29T07:51:06.843 回答