Clarification question here.
I was originally attempting to concatenate two strings using the stringByAppendingString
method:
NSString *dataString = @",";
NSInteger i = 0;
NSString *cycleCountString = @"";
for (i = 0; i<[[self cycleList] count]; i++) {
cycleCountString = [NSString stringWithFormat:@"cycle#%d,",i];
[dataString stringByAppendingString:cycleCountString];
}
NSLog(@"DataString is: %@",dataString);
However, the NSLog was just outputing ",
" as if cycleCountString
was not being appended to dataString
.
After reading:http://stackoverflow.com/questions/510269/how-do-i-concatenate-strings-in-objective-c , I was able to fix the issue by instead doing a stringWithFromat
:
NSString *dataString = @",";
NSInteger i = 0;
NSString *cycleCountString = @"";
for (i = 0; i<[[self cycleList] count]; i++) {
cycleCountString = [NSString stringWithFormat:@"cycle#%d,",i];
dataString = [NSString stringWithFormat:@"%@%@",dataString,cycleCountString];
}
NSLog(@"DataString is: %@",dataString);
any idea why the previous method wasn't working? Does stringByAppendingString
not work the way I think it does?
thanks!