如何将 HTML 代码更改为 iPhone 符号

发布于 2024-11-03 22:40:01 字数 2359 浏览 2 评论 0原文

我编写了一个函数,可以将“›”、“«”等文本更改为符号“›”“«”,我想分享这个与 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;
}

I have written a function that changes texts like "", "«" to symbols "›" "«" and I want to share this function with stackoverflow users. If you have suggestions how to make this function better please write !!! Thank you !!!

- (NSString*) ChangeAccentsLettersToSymbols: (NSString*) strToCorrect {
    NSLog(@"ChangeAccentsLettersToSymbols Entered\n");
    static NSString * const codeMap[][2] = {
        {@"¡",    @"¡"},  {@"«",    @"«"},  {@"»",    @"»"},  {@"‹",   @"‹"},  
        {@"›",   @"›"},  {@"‚",    @"‚"},  {@"„",    @"„"},  {@"“",    @"“"},  
        {@"”",    @"”"},  {@"‘",    @"‘"},  {@"’",    @"’"},  {@"¢",     @"¢"},
        {@"£",    @"£"},  {@"¥",      @"¥"},  {@"€",     @"€"},  {@"¤",   @"¤"},  
        {@"ƒ",     @"ƒ"},  {@">",       @">"},  {@"<",       @"<"},  {@"÷",   @"÷"},  
        {@"°",      @"°"},  {@"¬",      @"¬"},  {@"±",   @"±"},  {@"µ",    @"µ"},
        {@"&",      @"&"},  {@"®",      @"®"},  {@"©",     @"©"},  {@"™",    @"™"},  
        {@"•",     @"•"},  {@"·",   @"·"},  {@"§",     @"§"},  {@"–",    @"–"},  
        {@"—",    @"—"},  {@"†",   @"†"},  {@"‡",   @"‡"},  {@"◊",      @"◊"},
        {@"↑",     @"↑"},  {@"↓",     @"↓"},  {@"←",     @"←"},  {@"→",     @"→"},  
        {@"↔",     @"↔"},  {@"¿",   @"¿"},  {@" ",     @" "},  {@""",     @"\""}
    };
    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;
}

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

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

发布评论

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

评论(1

回忆那么伤 2024-11-10 22:40:02

github 上有 repo -

https://github.com/mwaterfall/MWFeedParser

看看这个函数

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

的工作原理对我来说很好。

there is repo on github -

https://github.com/mwaterfall/MWFeedParser

look at this functions

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

its working fine for me.

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