Unoptimal, quick-and-dirty and string-format-dependent solution:
-(NSString*) getValueFromString:(NSString *)text forTag:(NSString*)tag withNextTag:(NSString*)nextTag
{
NSRange tagRange = [text rangeOfString:[tag stringByAppendingString:@": "]];
NSRange nextTagRange = [text rangeOfString:[nextTag stringByAppendingString:@":"]];
NSUInteger start = tagRange.location + tagRange.length;
NSUInteger length = nextTagRange.location - start - 1; //-1 to skip a space before the next tag name
return [text substringWithRange:NSMakeRange(start, length)];
}
Usage:
NSString *input = @"Model Name: Mac mini Model Identifier: Macmini6,1 Processor Name: Intel Core i5 Processor Speed: 2.5 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 3 MB Memory: 4 GB Boot ROM Version: MM61.0106.B03 SMC Version (system): 2.7f1 Serial Number (system): C07M81SWDWYL Hardware UUID: 3B2564A0-7F96-5774-9C93-E56769E9344D";
NSLog(@"test: %@", [self getValueFromString:input forTag:@"Processor Name" withNextTag:@"Speed"]);
Also, you could try to find information about regular expressions.