我对componentsSeparatedByString:
给我奇怪的结果有疑问。
使用此代码:
CCLOG(@" Found string %@",string);
tokens = [string componentsSeparatedByString:@"[,]"];
CCLOG(@" sanity %@", (NSString *)[tokens objectAtIndex:0]);
int type = [(NSString *)[tokens objectAtIndex:0] integerValue];
int x = [(NSString *)[tokens objectAtIndex:1] integerValue]; //<< breakpoint
我得到这个输出日志:
2013-03-03 21:29:39.184 Legends[33427:c07] Found string 1[0,5]
2013-03-03 21:29:39.185 Legends[33427:c07] sanity 1[0,5]
所以程序在最后一行中断是有道理的,因为数组标记中的第一个对象具有整个字符串,但不应该将字符串@"1[0,5]"
拆分为@"1"
@"0"
and@"5"
吗?