在Objective-C中...我想代表占位符char(%),但我的代码不...。

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

怎么了?

有帮助吗?

解决方案

尝试这个:

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

格式指定符的完整列表是 这里.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top