在Objective-C中有没有(stringByAppendingString:)字符串连接的快捷方式,或者一般使用NSString的快捷方式?
例如,我想做:
NSString *myString = @"This";
NSString *test = [myString stringByAppendingString:@" is just a test"];
更像是:
string myString = "This";
string test = myString + " is just a test";
我一直在看这篇文章,最后总是整理答案,找到一个简单的解决方案,可以根据需要处理尽可能多的变量:
[NSString stringWithFormat:@"%@/%@/%@", three, two, one];
例如:
NSString *urlForHttpGet = [NSString stringWithFormat:@"http://example.com/login/username/%@/userid/%i", userName, userId];
你可以使用NSArray as
NSString *string1=@"This"
NSString *string2=@"is just"
NSString *string3=@"a test"
NSArray *myStrings = [[NSArray alloc] initWithObjects:string1, string2, string3,nil];
NSString *fullLengthString = [myStrings componentsJoinedByString:@" "];
or
你可以使用
NSString *imageFullName=[NSString stringWithFormat:@"%@ %@ %@.", string1,string2,string3];