53

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?

Suchi
  • 9,989
  • 23
  • 68
  • 112
  • 2
    I already knew this method but couldn't remember its name. Thanks to your question, `google` helped me to find it back. – Colas Jan 23 '14 at 10:16

2 Answers2

135

There are many ways to do it, the simplest being

[yourArray componentsJoinedByString: @","]
17

Use NSArray's componentsJoinedByString: method.

NSArray *strings = ...;
NSString *combined = [strings componentsJoinedByString:@","];
ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123