设为首页 加入收藏

TOP

Objective-c在宏里拼接字符串
2014-11-23 19:25:59 来源: 作者: 【 】 浏览:13
Tags:Objective-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/"


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


最后,感谢万能的google,万能的stackoverflow。




】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C 语言中将字符串倒 输出 下一篇C语言学习之补码的深刻理解

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: