NSString *infix = @"4+23-54/543*23";
NSCharacterSet *operatorSet = [NSCharacterSet characterSetWithCharactersInString:@"+-*/"];
NSArray *tokens = [infix componentsSeparatedByCharactersInSet:operatorSet];
tokens
返回:
[@“4”,@“23”,@“54”,@“543”,@“23”]
我正在尝试在 Objective-C 中实现 Shutting Yard。如何使用运算符集标记中缀字符串而不从标记化中删除运算符集本身?
我需要的:
[@"4"、@"+"、@"23"、@"-"、@"54"、@"/"、@"543"、@"*"、@"23"]