This is my example NSStrings (parsed into an array), simplified.
One string object is processed as "STRING1, STRING2, then DATE TIME, then - A: VALUE", ex:
The name of first value, first 17/04/2013 11:30:00 - A:30.0
Well, I need to extract individual values ββSTRING or STRING, STRING:
The name of first value, first The name of second value Name of third value Fourth Fifth value
then DATE and TIME
17/04/2013 11:30:00 17/04/2013 11:00:00 17/04/2013 10:30:00 17/04/2013 09:40:00 17/04/2013 05:00:00
finally, the only VALUES value:
30.0 20.0 40.0 50.0 10.0
EDIT: I'm trying to use Martin R code for my parsed * allValues:
The *allValues array is something like: ( "The name of first value, first 17/04/2013 11:30:00 - A:30.0", "The name of second value 17/04/2013 11:00:00 - A:20.0", "Name of third value 17/04/2013 10:30:00 - A:40.0", "Fourth 17/04/2013 09:40:00 - A:50.0", "Fifth value 17/04/2013 05:00:00 - A:10.0" )
and here is the code to extract the individual values:
NSMutableArray *allValues = [parsedFeed valueForKey:@"values"]; for (int i=1; i < [allValues count]; i++) { NSString *string = [allValues objectAtIndex:i]; NSString *pattern = @"(.*) (\\d{2}/\\d{2}/\\d{4} \\d{2}:\\d{2}:\\d{2}) - A:(.*)"; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:NULL]; NSTextCheckingResult *match = [regex firstMatchInString:string options:0 range:NSMakeRange(0, [string length])]; if (match != nil) { NSString *s1 = [string substringWithRange:[match rangeAtIndex:1]]; NSString *s2 = [string substringWithRange:[match rangeAtIndex:2]]; NSString *s3 = [string substringWithRange:[match rangeAtIndex:3]]; NSLog(@"First part: %@", s1); NSLog(@"Second part: %@", s2); NSLog(@"Third part: %@", s3); } }
But in this case, I cannot get the result of NSLog ( match == nil ). What happened? Thanks!