简体   繁体   中英

Special character output in NSString Iphone

NSString * url;
NSString * device;
NSString * API;
API      = @"http://www.test/";
device   = @"test123";
url      = [NSString stringWithFormat:@"%@update.json?dev=%20%20%20%@", API, device];

I want the final url to http://www.test/update.json?dev=%20%20%20%20test123 ; However the above I get only http://www.test/update.json?dev=22020test123 ; I want those %20 be part of literal string of url. How can I accomplish that?

要生成%符号,因为它是一个特殊字符,您需要为NSString中的每个%放入%%

put \\ before every special character. That should work.

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