Hi, The below code is to get sub-strings from a string. You are going to love this below code which is very simple but very effective. I have used regular expression to get the sub strings.
- NSString *strTest = @"Hii how are you doing @Ravi , how do u do @Kiran where are you @Varun";
- NSError *error;
- NSRegularExpression *exp =[NSRegularExpression regularExpressionWithPattern:@"@[^ ]*" options:NSRegularExpressionCaseInsensitive error:&error];
- NSArray *s1= [exp matchesInString:strTest options:NSMatchingReportCompletion range:NSMakeRange(0, [strTest length]) ];
- [s1 enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- NSTextCheckingResult *result = obj;
- NSString *str = [strTest substringWithRange:result.range];
- NSLog(@"str %@",str);
- }];
For
such more Blogs you can visit to http://findnerd.com/NerdDigest
No comments:
Post a Comment