2012-01-23 75 views

回答

13

%符號(如浮點數和小數部分相似)之後添加0.2。

NSString *[email protected]"hello"; 
    NSMutableString *result=[NSString stringWithFormat:@"%.2d", sth.length]; 
0

使用此

NSMutableString *result=[NSString stringWithFormat:@"%.2d", sth.length]; 
5

這裏有一個簡單的方法,如果我正確地理解你的問題:

NSString *fish = @"Chips"; 
NSString *length = [NSString stringWithFormat:@"%02d",[fish length]]; 
NSLog(@"Chips length is %@",length); 

產地:

2012-01-23 10:42:20.316 TestApp[222:707] Chips length is 05 

的02指零墊長度爲2.你會親bably想檢查一下你的字符串的長度是不是99個字符。