问题
How do I use the % character literal in an NSString stringWithFormat?
I am trying to do: [NSString stringWithFormat:@"%%@,%@",string1,string2];
The first % does not show up.
回答1:
[NSString stringWithFormat:@"%%%@,%@",string1,string2];
回答2:
Two percent charicters, %%, will print as one %.
From the String Format Specifiers list.
回答3:
Try this:
[NSString stringWithFormat:@"%@%%",str1];
回答4:
Using % two times (as escape character) should give you what you need. An example printing %foo,bar would look like this
[NSString stringWithFormat:@"%%%@,%@", @"foo", @"bar"];
来源:https://stackoverflow.com/questions/9949908/how-do-i-use-character-in-nsstring-stringwithformat