2010년 9월 17일 금요일

Objective-C – Format Specifier in NSString

Objective-C – Format Specifier in NSString

Ususally we use the Format Specifier in NSLog() to show the debug output. For Example:
1NSString* name = @"Yuen Ying Kit";
2int age = 26;
3NSLog(@"My name is %@", name);
4NSLog(@"I am %i years old", age);


You will get a debug output like


List of Format Specifiers
01%@     NSString*
02%d     Signed Integer
03%i     Signed Integer
04%u     Unsigned Integer
05%f     Float / Double
06%x     Hexidecimal Integer
07%X     Hexidecimal Integer
08%o     Octal Integer
09%zu    size_t
10%p     Pointer
11%e     Float / Double (in scientific notation)
12%g     Float / Double (as %f or %e, based on value)
13%s     C String
14%.*s   Pascal String
15%c     Character
16%C     Unicode Character
17%ll    Long Long
18%llu   Unsigned Long Long
19%Lf    Long Double   

Reference: Eureka!

댓글 없음:

댓글 쓰기