explode_implode

版本 1.0.0.0 (2.3 KB) 作者: Sara Silva
Two functions: split string into pieces, join strings with delimiter in between.
3.8K 次下载
更新时间 2005/3/11

查看许可证

%EXPLODE Splits string into pieces.
% EXPLODE(STRING,DELIMITERS) returns a cell array with the pieces
% of STRING found between any of the characters in DELIMITERS.
%
% [SPLIT,NUMPIECES] = EXPLODE(STRING,DELIMITERS) also returns the
% number of pieces found in STRING.
%
% Input arguments:
% STRING - the string to split (string)
% DELIMITERS - the delimiter characters (string)
% Output arguments:
% SPLIT - the split string (cell array), each cell is a piece
% NUMPIECES - the number of pieces found (integer)
%
% Example:
% STRING = 'ab_c,d,e fgh'
% DELIMITERS = '_,'
% [SPLIT,NUMPIECES] = EXPLODE(STRING,DELIMITERS)
% SPLIT = 'ab' 'c' 'd' 'e fgh'
% NUMPIECES = 4
%
% See also IMPLODE, STRTOK
%
% Created: Sara Silva (sara@itqb.unl.pt) - 2002.04.30

%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
% Modified: Sara Silva (sara@dei.uc.pt) - 2005.03.11
% - implode did not work if the delimiter was whitespace, so
% line 36 was replaced by line 37.
% - thank you to Matthew Davidson for pointing this out
% (and providing the solution!)

引用格式

Sara Silva (2024). explode_implode (https://www.mathworks.com/matlabcentral/fileexchange/3028-explode_implode), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R10
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Characters and Strings 的更多信息
致谢

启发作品: rsplit

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0

implode did not work if the delimiter was whitespace, so line 36 was replaced by line 37. explode remains the same.

Thank you to Matthew Davidson for pointing this out (and providing the solution!)