目标C中连接NSString的快捷方式有什么捷径可以(stringByAppendingString:)目标-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贡献1830条经验 获得超3个赞
NSMutableString
appendString
NSArray
componentsJoinedByString
墨色风雨
TA贡献1853条经验 获得超6个赞
一种选择:
[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贡献1817条经验 获得超6个赞
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 关注
- 479 浏览
添加回答
举报
0/150
提交
取消