简体   繁体   中英

How do I use % character in NSString stringWithFormat

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.

[NSString stringWithFormat:@"%%%@,%@",string1,string2];

Two percent charicters, %%, will print as one %.

From the String Format Specifiers list.

试试这个:

   [NSString stringWithFormat:@"%@%%",str1];

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"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM