嗨这里是我的功能,但每当我尝试初始化和分配foo
它下降,你能告诉我为什么吗?为什么代码落在substringwithrange范围
-(NSString*)modifyTheCode:(NSString*) theCode{
if ([[theCode substringToIndex:1]isEqualToString:@"0"]) {
if ([theCode length] == 1) {
return @"0000000000";
}
NSString* foo = [[NSString alloc]initWithString:[theCode substringWithRange:NSMakeRange(2, [theCode length]-1)]];
return [self modifyTheCode:foo];
} else {
return theCode;
}
}
错误消息:
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.2 (8H7)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
它会删除第一个或最后一个字符吗?例如它应该为这个字符串“0abba”添加什么? – Csabi 2011-05-04 10:30:34
nope..index从0开始。假设你有一个5个字符的字符串,所以范围索引为0到4,substringWithRange应该从索引1到4获得字符串,right ... – Krishnabhadra 2011-05-04 10:33:12
如果你从索引2开始并给[字符串长度] - 1,您要求从索引2获得4个字符,这应该是2,3,4,5 .. – Krishnabhadra 2011-05-04 10:34:04