When to use NSScanner vs. componentsSeparatedByCharactersInSet: to tokenize NSString?

725 views Asked by At

I need to tokenize many strings on an iPhone. Obviously, resources are at a minimum. I have been using componentsSeparatedByCharactersInSet: to tokenize my strings, but it is slow. Would it be better to use NSScanner? What, generally, are the guidelines one should follow when choosing to use one or the other to tokenize?

1

There are 1 answers

0
Eimantas On BEST ANSWER

IMHO NSScanner is way more flexible than componentsSeparatedByCharactersInSet, so if you need more flexibility - use NSScanner. Regarding performance - you'd have to test for that. So if NSScanner is faster - it has flexibility AND performance advantage (although disadvantage on ease of use).