Mos*_*she 9 substring objective-c nsstring ios nsrange
如何从开头到指定字符选择字符串?
例如,在下面的新闻标题中......
someString = @"Los Angeles, California - Apple announces something, stock prices change."
如何选择Los Angeles, California -单独的字符串?(我希望在-("破折号")角色之前选择所有内容.
编辑:
说我的标题看起来像这样:
someString = @"Los Angeles, California - Apple announces something - stock prices change."
如何防止我的位置字符串看起来像这样:Los Angeles, California - Apple announces something?
编辑:
我的错误,我正在移除第一个破折号,然后重新发现字符串.我的错误是发布的答案有效.
moh*_*enr 23
NSRange rangeOfDash = [someString rangeOfString:@"-"];
substring = (rangeOfDash.location != NSNotFound) ? [someString substringToIndex:rangeOfDash.location] : nil;
Run Code Online (Sandbox Code Playgroud)
这台substring以nil是否有在没有划线someString.
| 归档时间: |
|
| 查看次数: |
10071 次 |
| 最近记录: |