iOS解码umlaut& $

时间:2012-06-29 07:49:17

标签: ios nsstring decode diacritics

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

  

@“f&#252r”

如何将其解码为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的类别。

1 个答案:

答案 0 :(得分:0)

尝试

[@"für" stringByDecodingHTMLEntities];

[@"für" gtm_stringByUnescapingFromHTML];

(请注意;

This category也适用于丢失的;