我正在尝试用未知索引替换一些字符,例如这样(我需要替换此Ă,Ŏ,Ĭ,ă,ŏ,ĭ和我的输入nsstring可以是任何东西):
(void)repairText:(NSString *)textToRepair{`
NSString *pom = textToRepair;`
int pomNum = [pom length];
NSLog(@"Input nsstring: %@",pom);
for (int a = 0; a<pomNum; a++) {
NSString *pomChar, *pomChar2;
pomChar = [pom substringFromIndex:a];
pomChar2 = [pomChar substringToIndex:(1)];
NSLog(@"Char to repair: %@",pomChar2);
if ([pomChar2 isEqual: @"Ă"] || [pomChar2 isEqual:@"Ŏ"] || [pomChar2 isEqual:@"Ĭ"] || [pomChar2 isEqual:@"ă"] || [pomChar2 isEqual:@"ŏ"] || [pomChar2 isEqual:@"ĭ"]) {
if ([pomChar2 isEqual:@"Ă"]) {
NSLog(@"Wrong big a");
}
if ([pomChar2 isEqual:@"Ŏ"]) {
NSLog(@"Wrong big o");
}
if ([pomChar2 isEqual:@"Ĭ"]) {
NSLog(@"Wrong big i");
}
if ([pomChar2 isEqual:@"ă"]) {
NSLog(@"Wrong small a");
}
if ([pomChar2 isEqual:@"ŏ"]) {
NSLog(@"Wrong small o");
}
if ([pomChar2 isEqual:@"ĭ"]) {
NSLog(@"Wrong small i");
}
} else {
NSLog(@"Good");
}
}
pom = [textToRepair stringByReplacingOccurrencesOfString:@"•" withString:@" kulka "];
pom = [textToRepair stringByReplacingOccurrencesOfString:@"¥" withString:@" jen "];
pom = [textToRepair stringByReplacingOccurrencesOfString:@"£" withString:@" libra "];
pom = [textToRepair stringByReplacingOccurrencesOfString:@"€" withString:@" euro "];
[self synthesize:pom];
}
但是我在使用“如果”时遇到了麻烦。如果有人知道这一点,请在这方面提供帮助。
最佳答案
NSString *str=@"ĂdsdaĬsd";
str=[str stringByReplacingOccurrencesOfString:@"Ă" withString:@""];
str=[str stringByReplacingOccurrencesOfString:@"Ĭ" withString:@""];
NSLog(@"%@",str);
O / p:dsdasd
关于ios - 如何用未知索引替换NSString中的特殊字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23129055/