2009-12-07 130 views
0

在Objective-C ... 我想代表占位符字符(%) ,但我的代码不....我如何设置占位符字符(%)?

NSString *base = @"<style type=\"test/css\">div{width:100\%}</style><body>%@</body>"; 
NSString *html = [NSString stringWithFormat:base, @"hello world"]; 
NSLog(@"%@",html); 
  • 期待:DIV {宽度:100%}
  • real:div {width:100}

有什么不对?

回答

4

试试这个:

NSString *base = @"<style type=\"test/css\">div{width:100%%}</style><body>%@</body>"; 

格式说明符的完整列表here