ios - 如何用未知索引替换 NSString 中的特殊字符

标签 ios objective-c nsstring

我正在尝试用这样的未知索引替换一些字符(我需要替换这个 Ă,Ŏ,Ĭ,ă,ŏ,ĭ 并且我的输入 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/

相关文章:

iphone - 音频文件不在 iPhone/iOS 中播放

ios - 从Firebase iOS SDK获取user_pseudo_id

objective-c - NSString到NSDate返回错误的日期

objective-c - 我如何将 NSString 转换为长值?

ios - 自动布局:在不知道高度约束的情况下隐藏 UIView

ios - UIImagepicker 显示图像捕获而不是视频录制

ios - 在swift中传递闭包作为函数中选择器使用的参数

ios - Spritekit bodyWithbodies 不起作用

objective-c - iOS截图部分画面

objective-c - 如何显示 NSString * 的最后一个字符