Tag Archives: string join

C++ || How To Join & Concatenate An Array/Vector/Container Into A Delimited String Using C++

The following is a module with functions which demonstrates how to join and concatenate an array/vector/container into a delimited string using C++.

The function demonstrated on this page joins a container and returns the concatenated string according to the separator(s). The delimiter separator is included in the returned string only if there is more than one element.

The separator can be either a single character or multiple characters. If no separating characters are specified, the string is joined using a comma (‘,’).


1. Join – Integer Array

The example below demonstrates the use of ‘Utils::join‘ to join an array into a delimiter separated string.

In this example, the default separator is used to join the array, which is a comma (‘,’).


2. Join – String Vector

The example below demonstrates the use of ‘Utils::join‘ to join a vector into a delimiter separated string.

In this example, a custom separator is used to join the vector.


3. Utils Namespace

The following is the Utils Namespace. Include this in your project to start using!


4. More Examples

Below are more examples demonstrating the use of the ‘Utils‘ Namespace. Don’t forget to include the module when running the examples!

QUICK NOTES:
The highlighted lines are sections of interest to look out for.

The code is heavily commented, so no further insight is necessary. If you have any questions, feel free to leave a comment below.