Home > vbmeg > functions > common > utility > implode.m

implode

PURPOSE ^

IMPLODE Joins strings with delimiter in between.

SYNOPSIS ^

function string=implode(pieces,delimiter)

DESCRIPTION ^

IMPLODE    Joins strings with delimiter in between.
   IMPLODE(PIECES,DELIMITER) returns a string containing all the
   strings in PIECES joined with the DELIMITER string in between.

   Input arguments:
      PIECES - the pieces of string to join (cell array), each cell is a piece
      DELIMITER - the delimiter string to put between the pieces (string)
   Output arguments:
      STRING - all the pieces joined with the delimiter in between (string)

   Example:
      PIECES = {'ab','c','d','e fgh'}
      DELIMITER = '->'
      STRING = IMPLODE(PIECES,DELIMITER)
      STRING = ab->c->d->e fgh

   See also EXPLODE, STRCAT

   Created: Sara Silva (sara@itqb.unl.pt) - 2002.08.25

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function string=implode(pieces,delimiter)
0002 %IMPLODE    Joins strings with delimiter in between.
0003 %   IMPLODE(PIECES,DELIMITER) returns a string containing all the
0004 %   strings in PIECES joined with the DELIMITER string in between.
0005 %
0006 %   Input arguments:
0007 %      PIECES - the pieces of string to join (cell array), each cell is a piece
0008 %      DELIMITER - the delimiter string to put between the pieces (string)
0009 %   Output arguments:
0010 %      STRING - all the pieces joined with the delimiter in between (string)
0011 %
0012 %   Example:
0013 %      PIECES = {'ab','c','d','e fgh'}
0014 %      DELIMITER = '->'
0015 %      STRING = IMPLODE(PIECES,DELIMITER)
0016 %      STRING = ab->c->d->e fgh
0017 %
0018 %   See also EXPLODE, STRCAT
0019 %
0020 %   Created: Sara Silva (sara@itqb.unl.pt) - 2002.08.25
0021 
0022 if isempty(pieces) % no pieces to join, return empty string
0023    string='';
0024    
0025 else % no need for delimiters yet, so far there's only one piece
0026    string=pieces{1};   
0027 end
0028 
0029 l=length(pieces);
0030 p=1;
0031 while p<l % more than one piece to join with the delimiter, the interesting case
0032    p=p+1;
0033     string=strcat(string,delimiter,pieces{p});
0034 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005