annotate toolboxes/FullBNT-1.0.7/KPMtools/strsplit.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function parts = strsplit(splitstr, str, option)
Daniel@0 2 %STRSPLIT Split string into pieces.
Daniel@0 3 %
Daniel@0 4 % STRSPLIT(SPLITSTR, STR, OPTION) splits the string STR at every occurrence
Daniel@0 5 % of SPLITSTR and returns the result as a cell array of strings. By default,
Daniel@0 6 % SPLITSTR is not included in the output.
Daniel@0 7 %
Daniel@0 8 % STRSPLIT(SPLITSTR, STR, OPTION) can be used to control how SPLITSTR is
Daniel@0 9 % included in the output. If OPTION is 'include', SPLITSTR will be included
Daniel@0 10 % as a separate string. If OPTION is 'append', SPLITSTR will be appended to
Daniel@0 11 % each output string, as if the input string was split at the position right
Daniel@0 12 % after the occurrence SPLITSTR. If OPTION is 'omit', SPLITSTR will not be
Daniel@0 13 % included in the output.
Daniel@0 14
Daniel@0 15 % Author: Peter J. Acklam
Daniel@0 16 % Time-stamp: 2004-09-22 08:48:01 +0200
Daniel@0 17 % E-mail: pjacklam@online.no
Daniel@0 18 % URL: http://home.online.no/~pjacklam
Daniel@0 19
Daniel@0 20 nargsin = nargin;
Daniel@0 21 error(nargchk(2, 3, nargsin));
Daniel@0 22 if nargsin < 3
Daniel@0 23 option = 'omit';
Daniel@0 24 else
Daniel@0 25 option = lower(option);
Daniel@0 26 end
Daniel@0 27
Daniel@0 28 splitlen = length(splitstr);
Daniel@0 29 parts = {};
Daniel@0 30
Daniel@0 31 while 1
Daniel@0 32
Daniel@0 33 k = strfind(str, splitstr);
Daniel@0 34 if isempty(k)
Daniel@0 35 parts{end+1} = str;
Daniel@0 36 break
Daniel@0 37 end
Daniel@0 38
Daniel@0 39 switch option
Daniel@0 40 case 'include'
Daniel@0 41 parts(end+1:end+2) = {str(1:k(1)-1), splitstr};
Daniel@0 42 case 'append'
Daniel@0 43 parts{end+1} = str(1 : k(1)+splitlen-1);
Daniel@0 44 case 'omit'
Daniel@0 45 parts{end+1} = str(1 : k(1)-1);
Daniel@0 46 otherwise
Daniel@0 47 error(['Invalid option string -- ', option]);
Daniel@0 48 end
Daniel@0 49
Daniel@0 50
Daniel@0 51 str = str(k(1)+splitlen : end);
Daniel@0 52
Daniel@0 53 end