Q:

Extract parts of a string

I have a lot of strings looking like this:

Soccer Livescore: (POR-SF) #Rio Ave vs #SC Braga: 2-1
Soccer Livescore: (ENG-FC) #Chester FC vs #Halifax: 1-0

How can i extract the string between the () and the ints on each side of the -?

A:

Here's the answer.
NSString *string =@"Soccer Livescore: (CONMEBOL-GS) #Rio Ave vs #SC Braga: 2-1";

NSRange range1 = [string rangeOfString:@"("];
NSRange range2 = [string rangeOfString:@")"];
range1.location = range1.location + 1;
range1.length = range2.location - range1.location;

NSString *scoreString = [string substringWithRange:NSMakeRange([string length]-3, 3)];
NSArray *scores = [scoreString componentsSeparatedByString:@"-"];

NSLog(@"%@ %d %d", [string substringWithRange:range1], [scores[0] intValue], [scores[1] intValue]);

Log result: CONMEBOL-GS 2 1

