问题
I am an Objective C newbie. I want to write a method that takes in an array of strings and returns a concatenated string, with a comma (,) in between each string. So if an array is {a b c d}, I want to return a,b,c,d.
What is the easiest way to do that?
回答1:
There are many ways to do it, the simplest being
[yourArray componentsJoinedByString: @","]
回答2:
Use NSArray's componentsJoinedByString: method.
NSArray *strings = ...;
NSString *combined = [strings componentsJoinedByString:@","];
来源:https://stackoverflow.com/questions/7654679/objective-c-how-to-concatenate-an-entire-array-of-strings