Cody

# Problem 41. Cell joiner

Solution 214359

Submitted on 8 Mar 2013 by Alfonso Nieto-Castanon
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% x = {'hello', 'basic', 'test', 'case'}; y_correct = 'hello basic test case'; assert(isequal(cellstr_joiner(x, ' '),y_correct))

/opt/mlsedu/matlab/R2013a/toolbox/matlab/strfun/strjoin.m Contents.m hex2dec.m native2unicode.m str2mat.m strncmpi.m base2dec.m hex2num.m num2hex.m str2num.m strread.m bin2dec.m int2str.m num2str.m strcat.m strrep.m blanks.m iscellstr.m regexp.m strcmp.m strsplit.m cellstr.m ischar.m regexpi.m strcmpi.m strtok.m char.m isletter.m regexprep.m strfind.m strtrim.m deblank.m isspace.m regexptranslate.m strings.m strvcat.m dec2base.m isstr.m setstr.m strjoin.m unicode2native.m dec2bin.m isstrprop.m sprintf.m strjust.m upper.m dec2hex.m lower.m sscanf.m strmatch.m findstr.m mat2str.m str2double.m strncmp.m <strong>strjoin</strong> Join cell array of strings into single string S = <strong>strjoin</strong>(C) constructs the string S by linking each string within cell array of strings C together with a space. S = <strong>strjoin</strong>(C, DELIMITER) constructs S by linking each element of C with the elements of DELIMITER. DELIMITER can be either a string or a cell array of strings having one fewer element than C. If DELIMITER is a string, then <strong>strjoin</strong> forms S by inserting DELIMITER between each element of C. DELIMITER can include any of these escape sequences: \\ Backslash \0 Null \a Alarm \b Backspace \f Form feed \n New line \r Carriage return \t Horizontal tab \v Vertical tab If DELIMITER is a cell array of strings, then <strong>strjoin</strong> forms S by interleaving the elements of DELIMITER and C. In this case, all characters in DELIMITER are inserted as literal text, and escape characters are not supported. Examples: c = {'one', 'two', 'three'}; % Join with space. strjoin(c) % 'one two three' % Join as a comma separated list. strjoin(c, ', ') % 'one, two, three' % Join with a cell array of strings DELIMITER. strjoin(c, {' + ', ' = '}) % 'one + two = three' See also strcat, strsplit. Reference page in Help browser doc strjoin

2   Pass
%% x = {'this', 'one', '', 'has', ' ', 'some tricky', 'stuff'}; y_correct = 'this one has some tricky stuff'; assert(isequal(cellstr_joiner(x, ' '),y_correct))

/opt/mlsedu/matlab/R2013a/toolbox/matlab/strfun/strjoin.m Contents.m hex2dec.m native2unicode.m str2mat.m strncmpi.m base2dec.m hex2num.m num2hex.m str2num.m strread.m bin2dec.m int2str.m num2str.m strcat.m strrep.m blanks.m iscellstr.m regexp.m strcmp.m strsplit.m cellstr.m ischar.m regexpi.m strcmpi.m strtok.m char.m isletter.m regexprep.m strfind.m strtrim.m deblank.m isspace.m regexptranslate.m strings.m strvcat.m dec2base.m isstr.m setstr.m strjoin.m unicode2native.m dec2bin.m isstrprop.m sprintf.m strjust.m upper.m dec2hex.m lower.m sscanf.m strmatch.m findstr.m mat2str.m str2double.m strncmp.m <strong>strjoin</strong> Join cell array of strings into single string S = <strong>strjoin</strong>(C) constructs the string S by linking each string within cell array of strings C together with a space. S = <strong>strjoin</strong>(C, DELIMITER) constructs S by linking each element of C with the elements of DELIMITER. DELIMITER can be either a string or a cell array of strings having one fewer element than C. If DELIMITER is a string, then <strong>strjoin</strong> forms S by inserting DELIMITER between each element of C. DELIMITER can include any of these escape sequences: \\ Backslash \0 Null \a Alarm \b Backspace \f Form feed \n New line \r Carriage return \t Horizontal tab \v Vertical tab If DELIMITER is a cell array of strings, then <strong>strjoin</strong> forms S by interleaving the elements of DELIMITER and C. In this case, all characters in DELIMITER are inserted as literal text, and escape characters are not supported. Examples: c = {'one', 'two', 'three'}; % Join with space. strjoin(c) % 'one two three' % Join as a comma separated list. strjoin(c, ', ') % 'one, two, three' % Join with a cell array of strings DELIMITER. strjoin(c, {' + ', ' = '}) % 'one + two = three' See also strcat, strsplit. Reference page in Help browser doc strjoin

3   Pass
%% x = {'delimiters', 'are', 'not', 'always', 'spaces'}; y_correct = 'delimiters?are?not?always?spaces'; assert(isequal(cellstr_joiner(x, '?'),y_correct))

/opt/mlsedu/matlab/R2013a/toolbox/matlab/strfun/strjoin.m Contents.m hex2dec.m native2unicode.m str2mat.m strncmpi.m base2dec.m hex2num.m num2hex.m str2num.m strread.m bin2dec.m int2str.m num2str.m strcat.m strrep.m blanks.m iscellstr.m regexp.m strcmp.m strsplit.m cellstr.m ischar.m regexpi.m strcmpi.m strtok.m char.m isletter.m regexprep.m strfind.m strtrim.m deblank.m isspace.m regexptranslate.m strings.m strvcat.m dec2base.m isstr.m setstr.m strjoin.m unicode2native.m dec2bin.m isstrprop.m sprintf.m strjust.m upper.m dec2hex.m lower.m sscanf.m strmatch.m findstr.m mat2str.m str2double.m strncmp.m <strong>strjoin</strong> Join cell array of strings into single string S = <strong>strjoin</strong>(C) constructs the string S by linking each string within cell array of strings C together with a space. S = <strong>strjoin</strong>(C, DELIMITER) constructs S by linking each element of C with the elements of DELIMITER. DELIMITER can be either a string or a cell array of strings having one fewer element than C. If DELIMITER is a string, then <strong>strjoin</strong> forms S by inserting DELIMITER between each element of C. DELIMITER can include any of these escape sequences: \\ Backslash \0 Null \a Alarm \b Backspace \f Form feed \n New line \r Carriage return \t Horizontal tab \v Vertical tab If DELIMITER is a cell array of strings, then <strong>strjoin</strong> forms S by interleaving the elements of DELIMITER and C. In this case, all characters in DELIMITER are inserted as literal text, and escape characters are not supported. Examples: c = {'one', 'two', 'three'}; % Join with space. strjoin(c) % 'one two three' % Join as a comma separated list. strjoin(c, ', ') % 'one, two, three' % Join with a cell array of strings DELIMITER. strjoin(c, {' + ', ' = '}) % 'one + two = three' See also strcat, strsplit. Reference page in Help browser doc strjoin