C
const char *const strs[] = {"one", "two", "three"};
int i = 0;
int size = 0;
char *out;
for (i=0;i<3;i++) {
size += strlen(strs[i]) + 1;
}
out = (char *)malloc(size);
strcpy(out, strs[0]);
for (i=1;i<3;i++) {
strcat(out, ",");
strcat(out, strs[i]);
}
C++
vector<string> strs = {"one", "two", "three"};
string out = accumulate(next(strs.begin()), strs.end(), strs[0],
[](const string &a, const string &b) {
return a + "," + b;
});
vector<string> strs = {"one", "two", "three"};
ostringstream os;
copy(strs.begin(), strs.end()-1, ostream_iterator<string>(os, ","));
os << *strs.rbegin();
string out = os.str();
CoffeeScript
strs = ['one','two','three']
out = strs.join ','
Java
List<String> strs = Arrays.asList("one", "two", "three");
String out = String.join(",", strs);
String[] strs = {"one", "two", "three"};
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String str : strs) {
if (first) {
first = false;
} else {
sb.append(",");
}
sb.append(str);
}
String out = sb.toString();
JavaScript
let strs = ['one','two','three']
let out = strs.join(',')
Kotlin
val strs = arrayOf("one", "two", "three")
val out = strs.joinToString(",")
Lua
strs = {"one", "two", "three"}
table.concat(strs, ",")
Objective-C
NSArray *strs = @[@"one", @"two", @"three"];
NSString *out = [strs componentsJoinedByString:@","];
Perl
@strs = qw(one two three);
$out = join ',', @strs;
PHP
$strs = array('one', 'two', 'three');
$out = implode(',', $strs);
Python
strs = ['one','two','three']
','.join(strs)
Ruby
strs = %w(one two three)
out = strs.join ','
Swift
let strs = ["one", "two", "three"]
let out = strs.joined(separator: ",")