Skip to content

AFNI/NIfTI Server

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

Doxygen Source Code Documentation


GetWord.m

Go to the documentation of this file.
00001 function [err,Word] = GetWord (S,n,D)
00002 %
00003 %   [err,Word] = GetWord (S,n,D)
00004 %
00005 %Purpose:
00006 %   Extracts the nth word from S using one of the characters in
00007 %   D as a delimiter.
00008 %   
00009 %   
00010 %Input Parameters:
00011 %   S : String such as 'Hello Jim | Munch', trailing blanks are removed
00012 %   n : the word number. if n is greater than the total number of words,
00013 %       an error message is spat out.
00014 %   D : (optional string)the delimiter(s) such as '|' or 'l |' 
00015 %       (the last one uses, l, a space or | as delimiters).
00016 %        The default delimiter is a space character.
00017 %   
00018 %Output Parameters:
00019 %   err : 0 No Problem
00020 %       : 1 Mucho Problems
00021 %   
00022 %   Word : the word number n as specified by the delimiters
00023 %      
00024 %More Info :
00025 %   
00026 %   strtok
00027 %   example:
00028 %      [err,Word] = GetWord ('Hello Jim | Munch',2)  
00029 %                               Word = Jim
00030 %      [err,Word] = GetWord ('Hello Jim | Munch',2,'|')
00031 %           Word = Munch
00032 %      [err,Word] = GetWord ('Hello Jim | Munch',2,'| l')
00033 %           Word = o
00034 %
00035 %
00036 %     Author : Ziad Saad
00037 %     Date : Mon Apr 06 15:14:49 CDT 1998 
00038 
00039 
00040 %Define the function name for easy referencing
00041 FuncName = 'GetWord';
00042 
00043 %initailize return variables
00044 err = 1;
00045 Word = '';
00046 
00047 if (nargin == 2),
00048         D = ' ';
00049 end
00050 
00051 if (n < 1),
00052         err = ErrEval(FuncName,'Err_Word number should be > 0');        return
00053 end
00054 
00055 S = deblank (S);
00056 
00057 %make sure that word number needed is not larger than the total number of words
00058 if (n > WordCount(S,D)),
00059         err = ErrEval(FuncName,'Err_Not that many words in S'); return;
00060 end
00061 
00062 Sdiff = S;
00063 i=1;
00064 while (i<=n & ~isempty(Sdiff))
00065         [Word,Sdiff] = strtok(Sdiff,D);
00066 i=i+1;
00067 end
00068 
00069 
00070 err = 0;
00071 return;
00072 
 

Powered by Plone

This site conforms to the following standards: