Recently I was shocked by the fact that two NSStrings that resemble each other on NSLog may be different. It is because sometimes NSString can contain a zero width space character. Be aware of that and consider:
1 |
#define ZERO_WIDTH_SPACE_STRING @"\u200B" |
To conquer this you should clean your string from zero width white space characters before comparing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
NSMutableString *eMailToAdd = [NSMutableString string]; NSMutableCharacterSet *charSet = \ [[NSCharacterSet whitespaceCharacterSet] mutableCopy]; //[charSet formUnionWithCharacterSet:\ [NSCharacterSet punctuationCharacterSet]]; NSString *rawStr = [[tokenField textField] text]; for (int i = 0; i < [rawStr length]; i++) { if (![charSet characterIsMember:\ [rawStr characterAtIndex:i]]) { [eMailToAdd appendFormat:\ @"%@",[NSString stringWithFormat:@"%c",\ [rawStr characterAtIndex:i]]]; } } |