Logo

Programming-Idioms

Concatenate elements of string list x joined by the separator ", " to create a single string y.
Implementation
Rust

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Rust implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "strings"
y := strings.Join(x, ", ")
y = ', '.join(x)
$y = implode(', ', $x);
String y = String.join(", ", x);
$y = join(", ", @x)
y = x.join(", ");
import std.array;
string y = x.join(", ");
y = x.join(', ');
var
  _x: Array of string;
  _y: String;
  i: Integer;
begin
  _y := ''; //initialize result to an empy string
  // assume _x is initialized to contain some values
  for i := Low(_x) to High(_x) do
  begin
    _y := _y + _x[i];
    if i < High(_x) then _y := _y + ';';
  end;
end;
import Data.List
y = intercalate ", " x
import qualified Data.Text as T
{-# LANGUAGE OverloadedStrings #-}
y :: T.Text
y = T.intercalate ", " x
y = x.join(", ")
y = Enum.join(x, ", ")
Y = string:join(X, ",").
(defvar y (format nil "~{~A~^, ~}" x))
y = table.concat(x, ", ")
string y = string.Join(", ", x);
with Ada.Containers.Indefinite_Vectors; use Ada.Containers;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
declare
   Last : Cursor := X.Last;
   Y : Unbounded_String;
         
begin
   for C in X.Iterate loop
      Y := Y & Element (C) & (if C = Last then "" else ", ");
   end loop;
end;
(setf y (format nil "~{~a~^,~}" x))
val y = x.mkString(",")
(clojure.string/join "," '("abc" "def" "ghi") )
#include <string>
#include <vector>
#include <sstream>
#include <iterator>
std::vector<std::string> x;
std::string y;
const char* const delim = ", ";

switch (x.size())
{
	case 0: y = "";   break;
	case 1: y = x[0]; break;
	default:
		std::ostringstream os;
		std::copy(x.begin(), x.end() - 1,
			std::ostream_iterator<std::string>(os, delim));
		os << *x.rbegin();
		y = os.str();
}
y = ', '.join(map(str, x))
#include <string.h>
#define DELIM ", "
#define L 64

char y[L] = {'\0'};

for (int i = 0; i < N; ++i)
{
    if (i && x[i][0])
        strcat(y, DELIM);
    
    strcat(y, x[i]);
}
(define y
  (foldr (lambda (a b)
           (if (string=? b "")
               a
               (string-append a ", " b)))
         ""
         x))
  write (unit=y,fmt='(*(A,:,", "))') x

Dim x = {"a", "b", "c", "d"}.ToList
Dim y = String.Join(",", x)
@import Foundation;
NSString y=[x componentsJoinedByString:@", "];
String y = x.join(', ')
(setf y (reduce (lambda (a b)
                   (concatenate 'string a ", " b))
                 x))
val y = listOf(x).joinToString(", ")
y := x joinSeparatedBy: ', '.
', ' join: #('abc' 'def' 'ghi')
import java.util.ArrayList;
String y = "";
for(int index = 0; index < x.size(); index++) {
	if(index != 0) {
		y += ", ";
	}
	y += x.get(index);
}
#include <string>
#include <vector>
#include <ranges>
using namespace std::ranges;
y = x | views::join_with(',') | to<std::string>();