如何在Objective-C中检查字符是否为数字? [英] How to check whether a char is digit or not in Objective-C?

查看:71
本文介绍了如何在Objective-C中检查字符是否为数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查一个字符是否是数字.

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

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

我需要确定 'c' 是否为数字.我如何在 Objective-C 中实现这个检查?

I need to find out if 'c' is a digit or not. How can I implement this check in Objective-C?

推荐答案

在标准 C 中有一个函数 int isdigit( int ch ); 定义在 "ctype.h" 中.如果 ch 是数字,它将返回非零 (TRUE).

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.

您也可以手动检查:

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

这篇关于如何在Objective-C中检查字符是否为数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆