目標(biāo)C中連接NSString的快捷方式有什么捷徑可以(stringByAppendingString:)目標(biāo)-C中的字符串連接,或用于使用NSString總體而言?例如,我想做:NSString *myString = @"This";NSString *test = [myString stringByAppendingString:@" is just a test"];更像是:string myString = "This";string test = myString + " is just a test";
3 回答

牛魔王的故事
TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊
NSMutableString
appendString
NSArray
componentsJoinedByString

墨色風(fēng)雨
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
一種選擇:
[NSString stringWithFormat:@"%@/%@/%@", one, two, three];
另一種選擇:
NSLog(@"%@", [Util append:one, @" ", two, nil]); // "one two"NSLog(@"%@", [Util append:three, @"/", two, @"/", one, nil]); // three/two/one
+ (NSString *) append:(id) first, ...{ NSString * result = @""; id eachArg; va_list alist; if(first) { result = [result stringByAppendingString:first]; va_start(alist, first); while (eachArg = va_arg(alist, id)) result = [result stringByAppendingString:eachArg]; va_end(alist); } return result;}

慕的地6264312
TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊
NSString *joinedFromLiterals = @"ONE " @"MILLION " @"YEARS " @"DUNGEON!!!";
#define STRINGA @"Also, I don't know "#define STRINGB @"where food comes from."#define JOINED STRINGA STRINGB
- 3 回答
- 0 關(guān)注
- 524 瀏覽
添加回答
舉報(bào)
0/150
提交
取消