减去2个字符串

Bap*_*apu 1 iphone objective-c

我有一个字符串说例如@"012"我有另一个字符串@"02".如何在iPhone Objective-C中提取2个字符串的差异.我只需要从第一个字符串中删除第二个字符串中字符的存在.答案为"1".

Dav*_*ong 12

更短:

NSString* s1 = @"012";
NSString* s2 = @"02";
NSCharacterSet * set = [NSCharacterSet characterSetWithCharactersInString:s2];
NSString * final = [[s1 componentsSeparatedByCharactersInSet:set] componentsJoinedByString:@""];
NSLog(@"Final: %@", final);
Run Code Online (Sandbox Code Playgroud)

这样可以保留原始字符串中字符的顺序.