Advertisement
Guest User

Untitled

a guest
May 5th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. NSString *input = @"Sodium Nitrite E250 is a food additive ...";
  2. for (NSString *str in @[ @"E100", @"E101", @"E1500" ])
  3. if ([input rangeOfString:str].location != NSNotFound) {
  4. // do something
  5. }
  6.  
  7. NSArray *ary = [NSArray arrayWithObjects:@"E250", nil]; // String Data to find in String
  8. NSMutableArray *aryFoundData = [[NSMutableArray alloc]init];
  9.  
  10. for (int i=0; i<ary.count; i++) {
  11. NSString *str = @"Your String E250";
  12. if ([str containsString:[ary objectAtIndex:i]]) {
  13. [aryFoundData addObject:[ary objectAtIndex:i]];
  14. }
  15. }
  16.  
  17. // Now aryFoundData contains all the data which are available in string
  18.  
  19. NSString *testString = @"Sodium Nitrite E250 is a food additive that gives cured meats, such as ham E103, bacon, hot dogs, frankfurters, smoked fish E1255 corned beef, their characteristic red colour and flavour.";
  20.  
  21. NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@"E\d+" options:0 error:nil];
  22.  
  23. [regex enumerateMatchesInString:testString options:0 range:NSMakeRange(0, testString.length) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
  24. NSLog(@"%@", [testString substringWithRange:result.range]);
  25. }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement