Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get sub strings from a string using Regular Expression

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 1.80k
    Comment on it

    Hi, The below code is to get substrings 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);
    
        }];
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: