Reputation: 29886
I have the following
NSString *timeString = [NSString stringWithFormat:@"%i", time];
NSLog(@"Timestring is %@", timeString);
NSLog(@"the character at 1 is %d", [timeString characterAtIndex:1]);
and get the following in the print outs
Timestring is 59
the character at 1 is 57
If I print out characterAtIndex:0 it prints out
Timestring is 59
the character at 0 is 53
I think it is printing out the char representation of the number.
How could I do this so that I can extract both numbers from e.g. 60 and use the 6 and the 0 to set an image.
e.g. @"%d.png"
Upvotes: 0
Views: 1915
Reputation: 170829
format specifier %d make nslog to treat corresponding value as integer, so in your case char value is treated as integer and integer value printed. To output actual character use %c specifier:
NSLog(@"the character at 1 is %c", [timeString characterAtIndex:1]);
Upvotes: 4