我的字符串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");
        }
当字符串确实包含逗号分隔时它工作正常但当没有逗号时崩溃我希望日志说"Substring not found"?但是我明白了[__NSCFNumber rangeOfString:]: unrecognized selector sent to instance 0x1d533500