我写了一种功能,即修改“›
”、“«
至符号“›”““<>,”等,我希望与中流用户分享这一功能。 如果你建议如何更好地发挥这一作用,请写! 谢谢!
- (NSString*) ChangeAccentsLettersToSymbols: (NSString*) strToCorrect {
NSLog(@"ChangeAccentsLettersToSymbols Entered
");
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;
}