我有一个字符串 “AA - 人的头衔”
如何获取“-”之前的部分?
输出应该是“AA”
此外,如果输入没有“-”,则输出应该为零
最佳答案
NSInteger hyphenStart = [theString rangeOfString:@" - "].location;
if(hyphenStart == NSNotFound)
return nil;
return [theString substringToIndex:hyphenStart];
关于Objective-C 字符串操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3239764/