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: "S开发者_开发百科OCK OUT ARRAY: sock -i /Users/Username/sock/Main.sock -r 960 -as 2 -g 2.2 -il -id"
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);
精彩评论