How to check whether a char is digit or not in Objective-C?

前端 未结 6 1331
一向
一向 2021-02-05 10:46

I need to check if a char is digit or not.

NSString *strTest=@\"Test55\";
char c =[strTest characterAtIndex:4];

I need to find out if \'c\' is

6条回答
  •  孤街浪徒
    2021-02-05 10:53

    In standard C there is a function int isdigit( int ch ); defined in "ctype.h". It will return nonzero (TRUE) if ch is a digit.

    Also you can check it manually:

    if(c>='0' && c<='9')
    {
      //c is digit
    }
    

提交回复
热议问题