Home > utility > captalize.m

captalize

PURPOSE ^

capalize: Captalize each word of a given sentence

SYNOPSIS ^

function out = capalize(in)

DESCRIPTION ^

capalize: Captalize each word of a given sentence
    Usage: out = captalize(in)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out = capalize(in)
0002 %capalize: Captalize each word of a given sentence
0003 %    Usage: out = captalize(in)
0004 
0005 %    Multiple spaces are reduced to a single space too.
0006 
0007 %    Roger Jang 20000723
0008 
0009 if nargin<1, selfdemo; return; end
0010 
0011 if isempty(in),
0012     out = '';
0013     return;
0014 end
0015 
0016 i = 1;
0017 [token, rem] = strtok(in);
0018 while ~isempty(token)
0019     extracted{i} = token;
0020     i = i+1;
0021     [token, rem] = strtok(rem);
0022 end
0023 
0024 for i = 1:length(extracted),
0025     string = extracted{i};
0026     new_string = [upper(string(1)), string(2:end)];
0027     extracted{i} = new_string;
0028 end
0029 
0030 out = extracted{1};
0031 for i = 2:length(extracted),
0032     out = [out, ' ', extracted{i}];
0033 end
0034 
0035 % ====== Self demo
0036 function selfdemo
0037 input = 'this is A test for Me too';
0038 output = feval(mfilename, input);
0039 fprintf('input = %s\n', input);
0040 fprintf('output = %s\n', output);

Generated on Tue 01-Jun-2010 09:50:34 by m2html © 2003