0

Does anyone know of an easy way to re-format an NSArray as a typical NSString?

I'm basically building an array of objects (that have all been converted to NSString and aded to the NSArray) and if I NSLog the array I get this...

NSLog(@"SOCK OUT ARRAY: %@", sockOut);

SOCK OUT ARRAY: (
    sock,
    " -i /Users/Username/sock/Main.sock",
    " -r 960",
    " -as 2",
    " -g 2.2",
    " -il",
    " -id"
)

But what I need is to basically deconstruct the array as if I was to NSLog like this...

NSLog(@"SOCK OUT ARRAY: %@%@%@%@%@%@%@", arg1, arg2, arg3, arg4, arg5, arg6, arg7);

Which would produce: "SOCK OUT ARRAY: sock -i /Users/Username/sock/Main.sock -r 960 -as 2 -g 2.2 -il -id"

jscs
  • 63,694
  • 13
  • 151
  • 195
crewshin
  • 765
  • 9
  • 22
  • Sorry all. I don't know why my search didn't give me this result the first two times I tried searching. This method worked PERFECTLY. http://stackoverflow.com/questions/2386834/how-to-convert-nsarray-into-nsstring [inputNSArryGoesHere componentsJoinedByString: @","] – crewshin Feb 08 '11 at 18:20

1 Answers1

1

Assuming that first element (sock) is also an NSString, you want -[NSArray componentsJoinedByString:], which returns a string containing the elements of the array with a given separator between elements:

NSString *strSockOut = [sockOut componentsJoinedByString:@" "];
NSLog(@"SOCK OUT ARRAY: %@", strSockOut);