Victor John Victor John - 3 months ago 18
Objective-C Question

How can I compare the two special symbols with equality between @"+" and @"+" in iOS?

Accepted a special symbol through UITextField, likes symbol +, I want to compare them with equality. @"+" does not equal @"+". @"+" by UITextField, @"+" by inputing on Xcode.But how can I compare them ? Any help is appreciated!

Answer

You can achieve it by NSCharecterSet.

NSString *string = <your string>;

NSString *specialCharacterString = @"++";
NSCharacterSet *specialCharacterSet = [NSCharacterSet
                                       characterSetWithCharactersInString:specialCharacterString];

if ([string rangeOfCharacterFromSet:specialCharacterSet].length) {                
    NSLog(@"Success");
}
Comments