我试图搜索,但我认为我的谷歌技能不够好,所以我要求人们提供帮助.我正在扫描一个字符串并取出每个元素.我需要找出它的数字或文字.我以这种方式做了检查:
// Try to convert to double
@try{
double whatever=[myString doubleValue];
// If text is stored in myString, then it should throw an exception
} @catch (NSException *e){
// Do whatever I need, but here I know that it's text, not a number
}
Run Code Online (Sandbox Code Playgroud)
但是我发现Objective-C没有抛出异常,它只返回0.我不能依赖于用户不会使用零作为输入的事实,我该怎么办?
在此先感谢,我很确定有这样的踏板,我只是没有找到它们......