How do I get the substring between braces?

ios, nsstring, objective-c, substring

Solution

NSString *myString = @"{53} balloons";
NSRange start = [myString rangeOfString:@"{"];
NSRange end = [myString rangeOfString:@"}"];
if (start.location != NSNotFound && end.location != NSNotFound && end.location > start.location) {
    NSString *betweenBraces = [myString substringWithRange:NSMakeRange(start.location+1, end.location-(start.location+1))];
}

edit: Added range check, thx to Keab42 - good point.

Problem

I have a string as this. ``` NSString *myString = @"{53} balloons"; ``` How do I get the substring `53` ?

Original source

Related problems