Doxygen Source Code Documentation
WordCount.m
Go to the documentation of this file.00001 function [N] = WordCount (S,D)
00002 %
00003 % [N] = WordCount (S,[D])
00004 %
00005 %Purpose:
00006 % Counts the number of words in S that are delimited by D
00007 %
00008 %
00009 %Input Parameters:
00010 % S a string, trailing blanks are removed
00011 % D (optional) a series of characters to be used as delimiters like
00012 % ' |' for a space or | as delimiters or '|' for | as a delimiter only
00013 % default is ' '
00014 %
00015 %Output Parameters:
00016 % N number of words
00017 %
00018 %
00019 %More Info :
00020 % see also GetWord, WordNumber
00021 % S = 'Hi Ya | Freak '
00022 % WordCount(S,'|') -> 2
00023 % S = 'Hi Ya Freak '
00024 % WordCount(S) -> 3
00025 %
00026 % Author : Ziad Saad
00027 % Date : Mon Apr 13 15:53:41 CDT 1998
00028
00029
00030 %Define the function name for easy referencing
00031 FuncName = 'WordCount';
00032
00033 %initailize return variables
00034 N = [];
00035
00036 if (nargin == 1),
00037 D = ' ';
00038 end
00039
00040 S = deblank (S);
00041
00042 Sdiff = S;
00043 N=0;
00044
00045
00046 while (~isempty(Sdiff))
00047 [Word,Sdiff] = strtok(Sdiff,D);
00048 N=N+1;
00049 end
00050
00051
00052
00053
00054 return;
00055