
function res = explode(separator, str, drop_empty_strings) 


    if nargin<3
        drop_empty_strings = false;
    end
    
    
    k = strfind(str, separator);
    
    out_i = 1;
    if (~isempty(k))
       
     
        pieces = length(k);       
        if ~drop_empty_strings
            res = cell(1, pieces);
        else
            res = cell(1, 0);       % when drop_empty_strings then we dont know the number of words
        end
        
        
        prev_end = 0;
        
        for i = 1:pieces
           
            curr_end = k(i);
            % res(1, i) = cellstr(str(prev_end+1 : curr_end-1));
                   
                        
            piece = str(prev_end+1 : curr_end-1);
            if ~drop_empty_strings || (~isempty(piece))
                res(1, out_i) = cellstr(piece);
                out_i = out_i + 1;
            end
            
            prev_end = curr_end;     
            
        end
        
        piece = str(prev_end+1 : length(str));
        if ~drop_empty_strings || (~isempty(piece))
            res(1, out_i) = cellstr(piece);
            % out_i = out_i + 1;
        end
        
    else        % if (~isempty(k))  
        
        if ~drop_empty_strings || (~isempty(str))
            res = cellstr(str);        
        else
            res = cell(0);
        end
        
    end        % if (~isempty(k))
    


end
