Use whatever is the most convenient.... likely NSScanner.  Something like:

scanUpToCharacterFromSet: using the decimalDigitCharacterSet (see
NSCharacterSet), then ask the NSScanner if it -isAtEnd.  You might want to
trim whitespace off front and back?

The reality is that the performance hit of using an NSScanner to scan
through a string vs. writing some other random means of doing so is not
worth worrying about in the context of a WebObjects application.  If you had
to scan through a million strings all at once or had to scan through several
thousand characters per operation, it would be enough to matter.

However, in a web based application, there are so many other potential and
real bottle necks that optimizing string scanning in this context is a waste
of time as it won't be noticeable.

b.bum

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

Reply via email to