Wolfram Research

Function Repository Resource:

ToTitleCase (1.0.0) current version: 1.0.1 »

Source Notebook

Convert strings from sentence-style capitalization to title-style capitalization

Contributed by: Jon McLoone  |  Jon McLoone

ResourceFunction["ToTitleCase"][text]

changes the case of text to be suitable for a title.

Details and Options

ResourceFunction["ToTitleCase"] broadly follows the AP Stylebook: The first, last and principal words are given capitals. Prepositions and conjunctions of fewer than four letters are lower-case.
ResourceFunction["ToTitleCase"] accepts the following options:
"LowerCaseWords"(see below)words to put in lower case when not first or last
"UpperCaseWords"{}words to always return in upper case
The default value for the option "LowerCaseWords" is {"a", "aff", "an", "and", "as", "at", "bar", "ben", "but", "by", "cum", "d", "de", "des", "di", "ere", "et", "ex", "fer", "for", "if", "in", "mid", "nor", "now", "o", "of", "off", "on", "or", "out", "per", "pro", "qua", "re", "so", "sur", "tae", "the", "tho", "to", "ubi", "up", "vel", "via", "why", "yet"}.

Examples

Basic Examples (3) 

ToTitleCase changes most words to start with an uppercase letter with other letters lowercase:

In[1]:=
ResourceFunction["ToTitleCase"]["alien life DISCOVERED!"]
Out[1]=

Prepositions and conjunctions of fewer than four letters are lowercase:

In[2]:=
ResourceFunction["ToTitleCase"]["aliens arrive on the earth!"]
Out[2]=

But the first and last word are always capitalized:

In[3]:=
ResourceFunction["ToTitleCase"]["The aliens move on!"]
Out[3]=

Options (2) 

ToTitleCase does not know about acronyms. To control their case, use "UpperCaseWords":

In[4]:=
ResourceFunction["ToTitleCase"]["best broadcaster - the bbc or cnn?", "UpperCaseWords" -> {"BBC", "CNN"}]
Out[4]=

To extend or reduce the list of words that are lowercase in ToTitleCase, use "LowerCaseWords":

In[5]:=
ResourceFunction["ToTitleCase"]["aliens arrive on the earth!", "LowerCaseWords" -> {}]
Out[5]=

Version History

  • 1.0.1 – 25 April 2022
  • 1.0.0 – 28 March 2022

Source Metadata

Related Resources

License Information