开发者

Character at index issue

开发者 https://www.devze.com 2023-02-02 04:55 出处:网络
I have the following NSString *timeString = [NSString stringWithFormat:@\"%i\", time]; NSLog(@\"Timestring is %@\", timeString);

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 charac开发者_JS百科ter 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"


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]);
0

精彩评论

暂无评论...
验证码 换一张
取 消