annotate _FullBNT/KPMtools/strsplit.m @ 9:4ea6619cb3f5 tip

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