is it possible to implement MATLAB strtrim() equivalent from this matlabexchange link?

View: New views
1 Messages — Rating Filter:   Alert me  

is it possible to implement MATLAB strtrim() equivalent from this matlabexchange link?

by openopt@ukr.net :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3228&objectType=file

% (c) Primoz Cermelj, primoz.cermelj@email.si

% Last revision: 24.03.2003

%-----------------------------------------------------------



if (isempty(str)) | (nargin < 1)

    outstr = [];

    return

end

if nargin < 2 | isempty(trimType)

    trimType = 'both';

end

if isnumeric(str)

    outstr = str;

else

    ind = find( ~isspace(str) );        % indices of the non-space characters in the str    

    if isempty(ind)

        outstr = [];        

    else

        if strcmpi(trimType,'left')

            outstr = str( ind(1):end );

        elseif strcmpi(trimType,'right')

            outstr = str( 1:ind(end) );

        elseif strcmpi(trimType,'both')

            outstr = str( ind(1):ind(end) );

        elseif strcmpi(trimType,'full')

            outstr = str( ind );

        else

            error('Unknown string trimming operation');

        end        

    end

end

--------------------------------
MEX -file probably would be better
however, I guess in calculations strtrim is appiaring very seldom, so it doesn't matter