在 java 和 c# 中,字符串的拼接是直接用 + 來操作的。在 OC 中,說是有下面3種方法,
NSString* string; // 結果字符串
NSString* string1, string2; //已存在的字符串,需要將string1和string2連接起來
方法1:
在宏里拼接字符串:
#define API_SYSTEM @"http://"API_DOMAIN@"/system/"
#define API_USER @"http://"API_DOMAIN@"/user/"
API_SYSTEM 宏展開后是:
@"http://"@"www.49028c.com"@"/system/"
編譯器會自動將字符中連接起來,目的實現。
c語言下的實現:
#define API_SYSTEM "http://"API_DOMAIN"/system/"
#define API_USER "http://"API_DOMAIN"/user/"
新聞熱點
疑難解答