views:

90

answers:

1

In Objective-c ... I want represent placeholder char(%) but my code don't....

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

what is wrong?

+4  A: 

Try this:

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

The full list of format specifiers is here.

Alex