How can I select a string from the beginning until a specified character? How can I select a string from the beginning until a specified character? objective-c objective-c

How can I select a string from the beginning until a specified character?


NSRange rangeOfDash = [someString rangeOfString:@"-"];substring = (rangeOfDash.location != NSNotFound) ? [someString substringToIndex:rangeOfDash.location] : nil;

This sets the substring to nil if there's no dash in the someString.