tags:

views:

24

answers:

1

Hi guys,

I need a help from ur side for this.

actually I am having string like:

 NSString *str = @"Helloworld.123 456";

I need to get the characters one by one from the string and check whether it is an numeric value.

Is there any predefined method for this??

can anyone help to get out of his. Anyone's help will be much appreciated.

Thank you, Monish.

+1  A: 

To get a character from string you can use -characterAtIndex: method. And NSCharacterSet class allows you to check easily if given character is a number:

NSCharacterSet* numSet = [NSCharacterSet decimalDigitCharacterSet];
for (int i = 0; i < [str length];++i)
   if ([numSet characterIsMember: [str characterAtIndex:i]])
   // i-th character is a decimal digit

P.S. If your task is more general then just checking each single character then there also might be a more general built-in method for that task...

Vladimir