Long story short, I’m trying to parse an input string into ‘tokens’…..
I have complete control on where the tokens are placed, I can NSLog and see that my input string is entirely correctly formed (even down to the moment before attempting to tokenize).
For the purposes of this discussion, I’m building a simple calculator that can understand inputs, RPN them, and then the issue I’m having is with the tokenize and evaluate.
Anyway, let’s say my input string is
55:6:+:3:+:9:3:/:-
Where the ‘:’ have been inserted to purposefully create separators between each ‘token’. I then attempt to do something like
NSArray *chunks = [input componentsSeparatedByString:@":"];
And this invariably fails. If I try a ‘sizeof’ I consistently get 4 on the array, even though it should clearly be 9….
Thoughts?
The method works properly for your input as I’ve tested it here . You cannot use sizeof() to check the number of elements in an NSArray . sizeof of an NSArray pointer gives you the size of the pointer which is 4 bytes or 8 bytes of depending on whether you’re on a 32 or 64 bit machine . It is not the number of objects in the NSArray . If you want to check the number of objects in an NSArray use the count method .