第ä¸ç§æ¹å¼æ¯ä½¿ç¨NSScannerï¼
ãã1. æ´å½¢å¤æ
ãã- (BOOL)isPureInt:(NSString *)string{
ããNSScanner* scan = [NSScanner scannerWithString:string];
ããint val;
ããreturn [scan scanInt:&val] && [scan isAtEnd];
ãã}
ãã
ãã2.æµ®ç¹å½¢å¤æï¼
ãã- (BOOL)isPureFloat:(NSString *)string{
ããNSScanner* scan = [NSScanner scannerWithString:string];
ããfloat val;
ããreturn [scan scanFloat:&val] && [scan isAtEnd];
ãã}
ãã第äºç§æ¹å¼æ¯ä½¿ç¨å¾ªç¯å¤æ
ãã- (BOOL)isPureNumandCharacters:(NSString *)text
{
for(int i = 0; i < [text length]; ++i) {
ããint a = [text characterAtIndex:i];
if ([self isNum:a]){
ããcontinue;
} else {
return NO;
}
}
return YES;
}
ããæè
Cè¯è¨ä¸å¸¸ç¨çæ¹å¼.
ãã- (BOOL)isAllNum:(NSString *)string{
unichar c;
for (int i=0; i<string.length; i++) {
c=[string characterAtIndex:i];
if (!isdigit(c)) {
return NO;
}
}
return YES;
}
ãã第ä¸ç§æ¹å¼åæ¯ä½¿ç¨NSStringçtrimmingæ¹æ³
ãã- (BOOL)isPureNumandCharacters:(NSString *)string
{
string = [string stringByTrimmingCharactersInSet;[NSCharacterSet decimalDigitCharacterSet]];
ããif(string.length > 0)
{
ããreturn NO;
ãã}
return YES;
ãã}
ãã以ä¸ä¸ç§è½å¤å¸®å©å®ç°å¤ææ¯å¦ä¸ºæ°åçå½æ°ï¼iOSä¸æ²¡æç´æ¥å¤ææ¯å¦æ¯æ°åçæ¹æ³ï¼æ以åªè½å¤èªå·±æ·»å æ¹æ³å»å®ç°äº.
温馨提示:内容为网友见解,仅供参考