Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


RemoveExtension.m

Go to the documentation of this file.
00001 function [S, xtr] = RemoveExtension (S, xt)
00002 %
00003 %   [Sx, xtr] = RemoveExtension (S, [xt])
00004 %
00005 %Purpose:
00006 %   removes the extension xt from the end of S
00007 %   
00008 %   
00009 %Input Parameters:
00010 %   S : string
00011 %   xt: string of characters to be removed from the end of S
00012 %      xt can be | delimited strings. Trainling blanks will be removed
00013 %       if xt is empty (default) then the characters following and including 
00014 %       the last . will be removed.
00015 %   
00016 %Output Parameters:
00017 %   Sx : string, S without the extension
00018 %   xtr: The extension that was removed
00019 %      
00020 %Key Terms:
00021 %   
00022 %More Info :
00023 %   S = 'ajh_d.BRIK';
00024 %    [St, xtr] = RemoveExtension (S,'.HEAD|.BRIK')
00025 %   
00026 %   S = 'ajh_d';
00027 %   [St, xtr] = RemoveExtension (S,'.HEAD|.BRIK')
00028 %
00029 %     Author : Ziad Saad
00030 %     Date : Mon Oct 9 15:08:08 PDT 2000
00031 %     LBC/NIMH/ National Institutes of Health, Bethesda Maryland
00032 
00033 
00034 %Define the function name for easy referencing
00035 FuncName = 'RemoveExtension';
00036 
00037 if (nargin == 1),
00038         xt = '';
00039 end
00040 
00041 %find the number of words in xt
00042 n = WordCount(xt, '|');
00043 xtr = '';
00044 
00045 for (i=1:1:n),
00046         nS = length(S);
00047         %set the extension 
00048         [err, xc] = GetWord(xt, i, '|');xc = zdeblank(xc);
00049         nxc = length(xc);
00050         
00051         %lookfor extension
00052                 k = findstr(xc, S); nk = length(k);
00053                 if (~isempty(k)),
00054                         if ( (k(nk) + nxc -1) == nS), %extension is at the end of the name
00055                                 xtr = S(k(nk):nS); S = S(1:k(nk)-1); 
00056                         end
00057                 end
00058 end
00059 
00060 if (isempty(xt)),
00061         k = findstr(S,'.');
00062         if (isempty(k)),
00063                 return;
00064         else
00065                 xtr = S(k:length(S));
00066                 S = S(1:k-1);
00067                 return;
00068         end
00069 
00070 end
00071 
00072 
00073 return;
00074 
 

Powered by Plone

This site conforms to the following standards: