NSString is integer?

前端 未结 5 2033
自闭症患者
自闭症患者 2020-11-28 05:23

How to check if the content of a NSString is an integer value? Is there any readily available way?

There got to be some better way then doing something like this:

5条回答
  •  被撕碎了的回忆
    2020-11-28 06:09

    Something like this:

    NSScanner* scan = [NSScanner scannerWithString:toCheck]; 
    int val; 
    return [scan scanInt:&val] && [scan isAtEnd];
    

提交回复
热议问题