码迷,mamicode.com
首页 > 其他好文 > 详细

Objective-c在宏里拼接字符串

时间:2015-09-09 16:21:30      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

//正式服务器
#define API_DOMAIN @"www.online.com"
//测试服务器
//#define DOMAINXX @"192.168.0.10"


#define API_SYSTEM @"http://"API_DOMAIN@"/system/"
#define API_USER @"http://"API_DOMAIN@"/user/"


 API_SYSTEM 宏展开后是: @"http://"@"www.online.com"@"/system/"
编译器会自动将字符中连接起来,目的实现。


c语言下的实现:
//正式服务器
#define API_DOMAIN "www.online.com"
//测试服务器
//#define DOMAINXX "192.168.0.10"


#define API_SYSTEM "http://"API_DOMAIN"/system/"

#define API_USER "http://"API_DOMAIN"/user/"

 


参考:
http://stackoverflow.com/questions/8844981/how-to-expand-a-macro-into-nsstring-without-using-any-string-concatenation-at-ru

http://stackoverflow.com/questions/798221/c-macros-to-create-strings

 

Objective-c在宏里拼接字符串

标签:

原文地址:http://www.cnblogs.com/liaolijun/p/4794793.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!