I have a string that contains some text:
ProductImage [height:60]
and I want to extract just the 60 from it? The 60 is jus
You can use an NSScanner, or search using an NSRegularExpression.
NSScanner* sc = [NSScanner scannerWithString:s];
int num;
[sc scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet]
intoString:nil];
[sc scanInt:&num];
Or:
int num;
NSError* err = nil;
NSRegularExpression* r = [NSRegularExpression regularExpressionWithPattern:@"\\d+"
options:0
error:&err];
// error-checking omitted
for (NSTextCheckingResult* match in [r matchesInString:s
options:0
range:NSMakeRange(0, [s length])])
num = [[s substringWithRange: [match range]] intValue];