This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
Idiom #53 Join a list of strings
Concatenate elements of string list x joined by the separator ", " to create a single string y.

- Ada
- C
- Clojure
- C++
- C++
- C#
- D
- Dart
- Elixir
- Erlang
- Fortran
- Go
- Groovy
- Haskell
- Haskell
- JS
- Java
- Java
- Java
- Kotlin
- Lisp
- Lisp
- Lisp
- Lua
- Obj-C
- PHP
- Pascal
- Perl
- Python
- Python
- Python
- Ruby
- Rust
- Scala
- Scheme
- Smalltalk
- Smalltalk
- VB
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();
}
write (unit=y,fmt='(*(A,:,", "))') x
This uses Fortran's internal write to write to the string y.
The star * in the format descriptor (an extension, not in the Fortran standard) makes sure that the format in the brackets following is repeated as often as possible, and the : means skip anything afterwards (here, the comma) if there are no more I/O items.
The star * in the format descriptor (an extension, not in the Fortran standard) makes sure that the format in the brackets following is repeated as often as possible, and the : means skip anything afterwards (here, the comma) if there are no more I/O items.
{-# LANGUAGE OverloadedStrings #-}
y :: T.Text
y = T.intercalate ", " x
The first line allows the string literal ", " to be a type other then type String. In this case it is automatically converted to type Text.
This version uses Text as a common replacement for the built-in String type.
The type annotation on the second line is optional and can be omitted.
This version uses Text as a common replacement for the built-in String type.
The type annotation on the second line is optional and can be omitted.