No BSD License  

Highlights from
initialcaps

5.0

5.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 2.26 KB File ID: #12432

initialcaps

by David Fass

 

28 Sep 2006 (Updated 10 Oct 2006)

Convert a string to initial caps format (initial capitals on all words).

| Watch this File

File Information
Description

INITIALCAPS Convert string to "initial caps" format (initial capitals on all words).

B = INITIALCAPS(A) converts the initial letter of all words in A to capitals, where A is a string. Only initial letters are affected.

B = INITIALCAPS(A,idx) converts only the words in A indexed by vector 'idx' to "initial caps" format. A "word" for these purposes is any string of letters separated by one or more non-letters, excluding apostrophes. Thus, the phrase
"don't talk to grown-ups" contains 5 words.

Examples: A = 'life, don''t talk to me about life.'
              y = initialcaps(A)
                  y =
                    Life, Don't Talk To Me About Life.

             y = initialcaps(A,1)
                  y =
                    Life, don't talk to me about life.

              y = initialcaps(A,[2 3])
                  y =
                    life, Don't Talk to me about life.

              y = initialcaps(A,[2,5:7])
                  y =
                    life, Don't talk to Me About Life.

Acknowledgments: Thanks to Jerome from France for the vectorized code (vastly nicer than my original clunker), and thanks to John D'Errico for the suggestion regarding inclusion of a second input argument.

See also UPPER, LOWER, HEADLINE.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
07 Oct 2006 John D'Errico

A useful tool.

I'm never happy though. Why not provide an option to allow the user to force all words in a sentence to be capitalized, or only the first word of every sentence?

Thus the default behavior of initial caps would be as it is currently, but the user could also specify an option to modify that behavior.

s = initialcaps(s,'sentence');

The calls below would be equivalent.

s = initialcaps(s);
s = initialcaps(s,'word');

Please login to add a comment or rating.
Updates
10 Oct 2006

Vectorization courtesy of Jerome. Added second input argument.

Tag Activity for this File
Tag Applied By Date/Time
strings David Fass 22 Oct 2008 08:41:29
initial capital David Fass 22 Oct 2008 08:41:29
initial capitals David Fass 22 Oct 2008 08:41:29
capitalization David Fass 22 Oct 2008 08:41:29
upper case David Fass 22 Oct 2008 08:41:29
lower c David Fass 22 Oct 2008 08:41:29

Contact us at files@mathworks.com