time | Calls | line |
|---|
| | 1 | function s = join(str, varargin)
|
| | 2 | % JOIN Append elements of a string array together
|
| | 3 | % NEWSTR = JOIN(STR) appends the elements of STR, placing a space
|
| | 4 | % character between consecutive strings, and returns the result as the
|
| | 5 | % output array NEWSTR. JOIN combines strings along the last dimension of
|
| | 6 | % STR not equal to 1. STR can be a string array, a character vector, or
|
| | 7 | % a cell array of character vectors. NEWSTR has the same data type as
|
| | 8 | % STR. If STR is a character vector, then STR and NEWSTR are identical.
|
| | 9 | %
|
| | 10 | % NEWSTR = JOIN(STR,DELIMITER) appends the elements of STR and places
|
| | 11 | % elements of DELIMITER between them. If STR and DELIMITER are string
|
| | 12 | % arrays or cell arrays, then DELIMITER must have one element less than
|
| | 13 | % STR along the dimension being joined. The size of every other
|
| | 14 | % dimension of DELIMITER either must be 1 or must match the size of the
|
| | 15 | % corresponding dimension of STR. The space character is the default
|
| | 16 | % value of DELIMITER.
|
| | 17 | %
|
| | 18 | % NEWSTR = JOIN(STR,DIM) appends the elements of STR along the dimension
|
| | 19 | % DIM. The default value of DIM is the last dimension of STR with a size
|
| | 20 | % that does not equal 1.
|
| | 21 | %
|
| | 22 | % NEWSTR = JOIN(STR,DELIMITER,DIM) appends the elements of STR along
|
| | 23 | % the dimension DIM and places elements of DELIMITER between the
|
| | 24 | % strings.
|
| | 25 | %
|
| | 26 | % Example:
|
| | 27 | % STR = ["John","Smith";"Mary","Jones"];
|
| | 28 | % join(STR)
|
| | 29 | %
|
| | 30 | % returns
|
| | 31 | %
|
| | 32 | % "John Smith"
|
| | 33 | % "Mary Jones"
|
| | 34 | %
|
| | 35 | % Example:
|
| | 36 | % STR = {'John','Smith';'Mary','Jones'};
|
| | 37 | % join(STR,1)
|
| | 38 | %
|
| | 39 | % returns
|
| | 40 | %
|
| | 41 | % 'John Mary' 'Smith Jones'
|
| | 42 | %
|
| | 43 | % Example:
|
| | 44 | % STR = ["x","y","z";"a","b","c"];
|
| | 45 | % DELIMITER = {' + ',' = ';' - ',' = '};
|
| | 46 | % join(STR,DELIMITER)
|
| | 47 | %
|
| | 48 | % returns
|
| | 49 | %
|
| | 50 | % "x + y = z"
|
| | 51 | % "a - b = c"
|
| | 52 | %
|
| | 53 | % See also SPLIT, STRING/PLUS, COMPOSE
|
| | 54 |
|
| | 55 | % Copyright 2015-2017 The MathWorks, Inc.
|
| | 56 |
|
| 3 | 57 | narginchk(1, 3);
|
< 0.001 | 3 | 58 | if ~isTextStrict(str)
|
| | 59 | firstInput = getString(message('MATLAB:string:FirstInput'));
|
| | 60 | error(message('MATLAB:string:MustBeCharCellArrayOrString', firstInput));
|
| 3 | 61 | end
|
| | 62 |
|
< 0.001 | 3 | 63 | try
|
< 0.001 | 3 | 64 | s = string(str);
|
< 0.001 | 3 | 65 | s = s.join(varargin{:});
|
| | 66 |
|
| 3 | 67 | if ischar(str)
|
| | 68 | s = str;
|
< 0.001 | 3 | 69 | elseif ~isstring(str)
|
< 0.001 | 3 | 70 | s = cellstr(s);
|
< 0.001 | 3 | 71 | end
|
| | 72 | catch E
|
| | 73 | throw(E);
|
| 3 | 74 | end
|
< 0.001 | 3 | 75 | end
|
Other subfunctions in this file are not included in this listing.