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。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM