Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slstrsplit
Home > sltoolbox > text > slstrsplit.m

slstrsplit

PURPOSE ^

SLSTRSPLIT splits a string into cell array of strings by delimiters

SYNOPSIS ^

function strs = slstrsplit(srcstr, delimiters)

DESCRIPTION ^

SLSTRSPLIT splits a string into cell array of strings by delimiters

 $ Syntax $
   - strs = slstrsplit(srcstr, delimiters)

 $ Arguments $
   - srcstr:       the source string
   - delimiters:   the array of delimiting chars

 $ Description $
   - strs = slstrsplit(srcstr, delimiters) splits the source string into
     a cell array of parts, which are delimited by the chars in
     delimiters. 
 
 $ Remarks $
   - If for adjacent delimiters, the between will not will extracted.
   - No further processing is applied, you can use functions like 
     slcompresstext to achieve these goals.
 
 $ History $
   - Created by Dahua Lin, on Aug 13, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:

SOURCE CODE ^

0001 function strs = slstrsplit(srcstr, delimiters)
0002 %SLSTRSPLIT splits a string into cell array of strings by delimiters
0003 %
0004 % $ Syntax $
0005 %   - strs = slstrsplit(srcstr, delimiters)
0006 %
0007 % $ Arguments $
0008 %   - srcstr:       the source string
0009 %   - delimiters:   the array of delimiting chars
0010 %
0011 % $ Description $
0012 %   - strs = slstrsplit(srcstr, delimiters) splits the source string into
0013 %     a cell array of parts, which are delimited by the chars in
0014 %     delimiters.
0015 %
0016 % $ Remarks $
0017 %   - If for adjacent delimiters, the between will not will extracted.
0018 %   - No further processing is applied, you can use functions like
0019 %     slcompresstext to achieve these goals.
0020 %
0021 % $ History $
0022 %   - Created by Dahua Lin, on Aug 13, 2006
0023 %
0024 
0025 %% determine delimiter positions
0026 
0027 n0 = length(srcstr);
0028 is_delimiter = false(n0, 1);
0029 
0030 nd = length(delimiters);
0031 for i = 1 : nd
0032     ch = delimiters(i);
0033     is_delimiter(srcstr == ch) = true;
0034 end
0035 
0036 dps = find(is_delimiter);
0037 dps = dps(:)';
0038 
0039 %% extract parts
0040 
0041 if isempty(dps)
0042     strs = {srcstr};
0043 else
0044     sps = [1, dps+1];
0045     eps = [dps-1, n0];
0046     fv = find(sps <= eps);
0047     if ~isempty(fv)    
0048         sps = sps(fv);
0049         eps = eps(fv);
0050         np = length(fv);
0051         strs = cell(np, 1);
0052         for i = 1 : np
0053             strs{i} = srcstr(sps(i):eps(i));
0054         end        
0055     else
0056         strs = {};
0057     end
0058 end
0059 
0060         
0061 
0062

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com