function joined=cosmo_strjoin(strings, delim)
% joins strings using a delimeter string
%
% joined=cosmo_strjoin(strings[, delim])
%
% Inputs:
% strings 1xP cell with strings to be joined. Each string should be a
% row vector of characters
% delim delimeter string, or a cell of strings. In the
% latter case delim should have P-1 elements. If omitted a
% single space character ' ' is used.
% delim can contain backslash-escaped characters that are
% interpreted by sprintf; for example '\t' represents a tab
% character, '\n' a newline character, and '\\' a backslash
% character
%
% Output
% joined the string formed by alternating between strings and delim;
% if delim is a string, joined=[strings{1} delim strings{2} ...
% strings{P}].
% if delim is a cell, joined=strings{1} delim{1} strings{2} ...
% strings{P}
%
% Examples:
% cosmo_strjoin({'a','b','c'})
% %|| 'a b c'
%
% cosmo_strjoin({'a','b','c'}, '>#<')
% %|| 'a>#<b>#<c'
%
% % '\\' is the escaped backslash character
% cosmo_strjoin({'a','b','c'}, '\\')
% %|| 'a\b\c'
%
% % use multiple delimiters
% cosmo_strjoin({'a','b','c'},{'*','='})
% %|| 'a*b=c'
%
% Notes:
% - this function implements similar functionality as matlab's strjoin
% function introduced in 2013. this function is provided for
% compatibility with older versions of matlab.
% - this function is the inverse of cosmo_strsplit
%
% See also: cosmo_strsplit
%
% # For CoSMoMVPA's copyright information and license terms, #
% # see the COPYING file distributed with CoSMoMVPA. #