How do I use % character in NSString stringWithFormat

╄→尐↘猪︶ㄣ 提交于 2019-12-10 15:11:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!