我有字符串JSON,有时看起来像@"2,18,27,29",叫做mayString.其他时候这个字符串只是@"2"(一个数字,没有逗号分隔)
我想使用以下代码测试字符串是否包含逗号:
NSRange range = [mayString rangeOfString:@","];
if (range.location != NSNotFound) {
NSLog (@"Substring found at: %d", range.location);
}
else{
NSLog (@"Substring not found");
}
Run Code Online (Sandbox Code Playgroud)
当字符串确实包含逗号分隔时它工作正常但是当没有逗号时崩溃我会期望日志说"Substring not found"?但是我得到[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1d533500
| 归档时间: |
|
| 查看次数: |
2080 次 |
| 最近记录: |