views:

68

answers:

2

Hi, everyone,

I want to ask a question about the objective C. Does the NSString * contains some functions to check the NSString * contains some string in the UITextField.text? For example

NSString *checkString = @"abcd%"

if(checkString contains '%') // I want this function
   return YES;
else
   return NO;
+2  A: 
if([checkString rangeOfString:@"%"].location != NSNotFound)
    // hooray!
Noah Witherspoon
A: 

You can use - (NSRange)rangeOfString:(NSString *)aString. The code will look something like:

NSRange range = [UITextField.text rangeOfString:@"!"];

if (range.length >= 0){
  NSLog(@"String contains '!'");
}
else {
  NSLog(@"No '!' found in string");
}
Sergei Lost