嗨這裏是我的功能,但每當我嘗試初始化和分配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