iphone - 如何将 HTML 代码更改为符号 iphone

标签 iphone html ios symbols

我写了一个函数,可以将“”、“«”等文本更改为符号“›”、“«”,我想分享这个函数与 stackoverflow 用户。如果您有如何改进此功能的建议,请写信!!!谢谢!!!

- (NSString*) ChangeAccentsLettersToSymbols: (NSString*) strToCorrect {
    NSLog(@"ChangeAccentsLettersToSymbols Entered\n");
    static NSString * const codeMap[][2] = {
        {@"¡",    @"¡"},  {@"«",    @"«"},  {@"»",    @"»"},  {@"‹",   @"‹"},  
        {@"›",   @"›"},  {@"‚",    @"‚"},  {@"„",    @"„"},  {@"“",    @"“"},  
        {@"”",    @"”"},  {@"‘",    @"‘"},  {@"’",    @"’"},  {@"¢",     @"¢"},
        {@"£",    @"£"},  {@"¥",      @"¥"},  {@"€",     @"€"},  {@"¤",   @"¤"},  
        {@"&fnof;",     @"ƒ"},  {@"&gt;",       @">"},  {@"&lt;",       @"<"},  {@"&divide;",   @"÷"},  
        {@"&deg;",      @"°"},  {@"&not;",      @"¬"},  {@"&plusmn;",   @"±"},  {@"&micro;",    @"µ"},
        {@"&amp;",      @"&"},  {@"&reg;",      @"®"},  {@"&copy;",     @"©"},  {@"&trade;",    @"™"},  
        {@"&bull;",     @"•"},  {@"&middot;",   @"·"},  {@"&sect;",     @"§"},  {@"&ndash;",    @"–"},  
        {@"&mdash;",    @"—"},  {@"&dagger;",   @"†"},  {@"&Dagger;",   @"‡"},  {@"&loz;",      @"◊"},
        {@"&uarr;",     @"↑"},  {@"&darr;",     @"↓"},  {@"&larr;",     @"←"},  {@"&rarr;",     @"→"},  
        {@"&harr;",     @"↔"},  {@"&iquest;",   @"¿"},  {@"&nbsp;",     @" "},  {@"&quot;",     @"\""}
    };
    int count = sizeof(codeMap)/sizeof(codeMap[0]);
    for( int i=0; i<count; ++i ) {
        strToCorrect = [ strToCorrect stringByReplacingOccurrencesOfString: codeMap[i][0] 
                                                                withString: codeMap[i][1] ];
    }

    for( int i=33; i<126; ++i) {
        NSString* whotToReplace = [NSString stringWithFormat:@"&#%d;", i];
        NSString* replaceWith   = [NSString stringWithFormat:@"%c", (char*)i ];
        strToCorrect = [strToCorrect stringByReplacingOccurrencesOfString: whotToReplace
                                                               withString: replaceWith ];
    }
    return strToCorrect;
}

最佳答案

github 上有 repo -

https://github.com/mwaterfall/MWFeedParser

看看这个函数

- (NSString *)stringByDecodingHTMLEntities;
- (NSString *)stringByEncodingHTMLEntities;

它对我来说工作正常。

关于iphone - 如何将 HTML 代码更改为符号 iphone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5814611/

相关文章:

iphone - 为 iPhone 开发者提供的最佳地理编码服务

iphone - 使用 FMDB 插入表失败

iphone - 如何调整 UILabel 的宽度以适合文本大小?

javascript - 为什么第二个对话打不开?

ios - 我已经在我的服务器上上传了 apple-app-site-association,用于后端服务

ios - 是否可以允许其他应用程序从我们的应用程序检索数据?

iphone - Sybase ULtralite DB 和 iOS 核心数据

php - 使用 PHP 通过 HTML 表单发送电子邮件附件

javascript - 当图像位于同一域时,Canvas 元素未呈现为 PNG(安全错误)

iOS 8 共享扩展附件 - Xcode - Swift