我在从字符串中删除特殊字符时遇到问题。我使用了以下代码。但是 dint 工作。请建议我更好的逻辑
- (NSString *)trimmedReciString:(NSString *)stringName
{
NSCharacterSet *myCharSet = [NSCharacterSet characterSetWithCharactersInString:@"-/:;()$&@\".,?!\'[]{}#%^*+=_|~<>€£¥•."];
for (int i = 0; i < [stringName length]; i++) {
unichar c = [stringName characterAtIndex:i];
if ([myCharSet characterIsMember:c]) {
NSLog(@"%@",[NSString stringWithFormat:@"%c",[stringName characterAtIndex:i]]);
stringName = [stringName stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%c",[stringName characterAtIndex:i]] withString:@""];
}
}
return stringName;
}