Objective c 客观c字串操作

Objective c 客观c字串操作,objective-c,nsstring,Objective C,Nsstring,我有一根绳子 “AA-此人的头衔” 我怎样才能得到'-'之前的零件 输出应为“AA” 另外,如果输入没有“-”,那么输出应该为零。请阅读类文档。这会给我“AA”还是“AA”?NSString类文档非常好,类具有很多功能。 NSInteger hyphenStart = [theString rangeOfString:@" - "].location; if(hyphenStart == NSNotFound) return nil; return [theString substrin

我有一根绳子 “AA-此人的头衔”

我怎样才能得到'-'之前的零件

输出应为“AA”


另外,如果输入没有“-”,那么输出应该为零。请阅读类文档。

这会给我“AA”还是“AA”?NSString类文档非常好,类具有很多功能。
NSInteger hyphenStart = [theString rangeOfString:@" - "].location;
if(hyphenStart == NSNotFound)
    return nil;
return [theString substringToIndex:hyphenStart];