Thank You for all of the helpful advice last friday. I think the is some
minor detail that I am overlooking. Anyway, here is the path I decided to
take...
I only need the first 3 characters in the string, so I simply used the
"substringToIndex:" method. No problem.
I then used the NSCharacterSet class to call the method
"characterSetWithCharactersInString:invertedSet" and assigned the result to
an NSCharacterSet object.
Next, I used the method rangeOfCharacterFromSet and assigned the result to
an NSRange object...
Here is the code...
NSString * aString;
NSCharacterSet * anInvertedCharSet;
NSRange * aRange;
In appendToResponse:inContext
aString = [aString substringToIndex:3]; //line114
anInvertedCharSet = [[NSCharacterSet
characterSetWithCharactersInString:@"0123456789"] invertedSet]; //line115
aRange = [aString rangeOfCharacterFromSet:anInvertedCharSet ]; //line116
if (aRange == nil) //line117
The flow of my logic is sound (or sound enough). The problem is, I seem to
be violating some ObjC rule with respect to assigning data types.
Henceforth, here is what happened when I compiled...
ThisFile.m: In function `-[ThisFile.m appendToResponse:inContext:]':
ThisFile.m:116: incompatible types in assignment
ThisFile.m:117: warning: comparison of distinct pointer types lacks a cast
ThisFile.m:77: warning: `aRange' might be used uninitialized in this
function
Now, in the online documentation, it says that the NSString method
"rangeOfCharacterFromSet" takes as it's argument an NSCharacterSet object
(in this case "NSCharcterSet * anInvertedCharSet"0 and returns an NSRange
object (in this case "NSRange * aRange"), so according to the docs, I
shouldn't be getting this error. That is obviously not the case. There must
be some detail I am overlooking. Any suggestions would be very helpful.
Thanks in advance,
Joshua
josh_feinstein wrote:
> I have an NSString object that I would like to test to make sure that it
> contains only numeric characters and no alpha characters. The test will
> happen almost everytime the user makes a request to the app, so I am
> trying to decide which is the tightest, quickest, most effiecient method
> to use. Should I convert the string into an NSNumber or NSArray or
> NSScanner class and what is the "best" method within one of these three
> classes to use?
>
> Thanks,
> Joshua