function extractedText = extractAfter(text,seperator) % extractAfter - cuts text from the end of a seperator up to the end of the text itself % usage: % extractedText = extractAfter(text,seperator) % input: % text is a string, a character array, or % a cell array of strings/character arrays % seperator is a single character or a character array. But it can also be % a number N. A cell array containing numbers or charaters is also possible. % output: % extractedText is text(end_position_of_the_first_seperator+1:end) or % in case of numbers text is cut as text(N+1:end). If text and seperator are % cell arrays they are processed pairwise. ## Copyright (C) 2022-2031 Andreas Stark ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, ## see . % test the number of input parameters. They have to be exactly 2. if (nargin~=2) error('extractAfter: function called with only one parameter. For additional information see help extractAfter.'); endif % free from cell if length is only 1 if (iscell(text) && length(text)==1) text=text{1}; endif if (iscell(seperator) && length(seperator)==1) seperator=seperator{1}; endif % convert parameters if (isstring(text)) text=char(text); % for a octave string implementation endif % test first parameter if (iscell(text)) valid=logical(sum(~cellfun('ischar',text))==0); % all cell entries have to be char arrays else valid=ischar(text); % text has to be char endif if (~valid) error('extractAfter: first argument has to be char or a cell array of chars. For additional information see help extractAfter.'); endif % test second parameter % all cell entries have to be char arrays or numbers if (iscell(seperator)) valid=(sum(~cellfun(@(x) ischar(x)||isscalar(x),seperator,'UniformOutput',true))==0); else valid=ischar(seperator)||isscalar(seperator); endif if (~valid) error('extractAfter: second argument has to be cell, char or number. For additional information see help extractAfter.'); endif % mutual changes if (iscell(seperator) && ischar(text)) text=repmat({text},size(seperator)); % multiply text if seperator is a cell elseif (iscell(text) && (ischar(seperator)||isscalar(seperator))) seperator=repmat({seperator},size(text)); % multiply seperator if text is a cell endif if (iscell(seperator) && iscell(text) && length(seperator)~=length(text)) error('extractAfter: cell length of text and seperator has to match'); endif % cellify to simplify programm flow if (ischar(seperator)||isscalar(seperator)) seperator={seperator}; endif if (ischar(text)) text={text}; endif % do the cuts if (iscell(text) && iscell(seperator)) n=length(text); for i=1:n if (ischar(seperator{i})) seperator(i)=min(strfind(text{i},seperator{i}))+length(seperator{i})-1; endif if (isempty(seperator(i))) seperator(i)=0; endif if (seperator{i}<=length(text{i})) text(i)=text{i}(seperator{i}+1:end); else error(sprintf('extractAfter: seperator exceeds the text length in position %i.',i)); endif endfor endif % free from cell if length is only 1 if (iscell(text) && length(text)==1) text=text{1}; endif % return values extractedText=text; end