function T = strntok(s, sep, n)
%
% Given string `S' which contains tokens separated by any of the characters
% in `SEP', return the Nth token. It is very bad to call this function on
% long strings with any tokens or to call it from loops which iterate many
% times. To use this function to extract successive tokens results in
% O(N-1)^2 operations for N tokens; use strtok instead!
%
% $Id: strntok.m,v 1.4 1998/11/09 20:19:23 dbyrne Exp $

% $Log: strntok.m,v $
% Revision 1.4  1998/11/09 20:19:23  dbyrne
% *** empty log message ***
%
% Revision 1.1  1998/05/17 14:10:53  dbyrne
% *** empty log message ***
%

if n == 1				% special case n == 1
    [T R] = strtok(s, sep);
    % If there's only one token there maybe no separator. See Help strtok.
    if isempty(T)
	T = R;
    end
else    
    for k = 1 : n
	[T, s] = strtok(s, sep);
    end
end

return;

