NSString *infix = @"4+23-54/543*23";
NSCharacterSet *operatorSet = [NSCharacterSet characterSetWithCharactersInString:@"+-*/"];
NSArray *tokens = [infix componentsSeparatedByCharactersInSet:operatorSet];
tokens
returns:
[@"4", @"23", @"54", @"543", @"23"]
I am trying to implement Shunting Yard in Objective-C. How can I tokenize the infix string with the operator set without removing the operator set itself from the tokenization?
What I need:
[@"4", @"+", @"23", @"-", @"54", @"/", @"543", @"*", @"23"]