如何将 HTML 代码更改为 iPhone 符号
我编写了一个函数,可以将“›
”、“«
”等文本更改为符号“›”“«”,我想分享这个与 stackoverflow 用户一起使用。如果您有如何使此功能更好的建议,请写信!谢谢 !!!
- (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;
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
github 上有 repo -
https://github.com/mwaterfall/MWFeedParser
看看这个函数
的工作原理对我来说很好。
there is repo on github -
https://github.com/mwaterfall/MWFeedParser
look at this functions
its working fine for me.