How to find number of special characters in sting in objective C

93 Views Asked by At

Help me find the same, tried searching many questions all I found was to check if the string contains a special character, but I want to find the number of special characters in a string in objective - c

1

There are 1 best solutions below

0
pravalikaGovinda On

NSString *abcd = @",;ab/bn']jkfg\"; NSString specialCharacterString = @"!~`@#$%^&-+();:={}[],.<>?\/\"\'"; int count = 0; for (NSUInteger i=0;i<[abcd length];i++){ for(NSUInteger j=0;j<[specialCharacterString length];j++){ if ([abcd characterAtIndex:i]==[specialCharacterString characterAtIndex:j]){ NSLog(@"found: %d", i); count++; } }