Wolfram Research

Function Repository Resource:

FromCamelCase

Source Notebook

Split camel case phrases into separate words

Contributed by: Jon McLoone  |  Jon McLoone

ResourceFunction["FromCamelCase"]["string"]

inserts spaces into string to convert camel case phrases into separate words.

Details and Options

The following options are supported:
ToLowerCaseFalsewhether words after the first word are changed to lower case
“SingleLetterWords"Falsewhether sequences of capital letters should be separated as words
"KnownWords"{}words to treat as complete before the camel case is analyzed
IgnoreCaseFalsewhether "KnownWords" must match case

Examples

Basic Examples (1) 

Wolfram Language built-in symbols are always written in camel case:

In[1]:=
ResourceFunction["FromCamelCase"]["ListLinePlot"]
Out[1]=

Options (2) 

The option ToLowerCase will also put all but the first word into lower case:

In[2]:=
ResourceFunction["FromCamelCase"]["ListLinePlot", ToLowerCase -> True]
Out[2]=

Blocks of capitals are considered part of the same word:

In[3]:=
ResourceFunction["FromCamelCase"]["NDSolveValue"]
Out[3]=

Use "SingleLetterWords"True to change this:

In[4]:=
ResourceFunction["FromCamelCase"]["NDSolveValue", "SingleLetterWords" -> True]
Out[4]=

Use "KnownWords" for groups of letters that should be treated as a single word, such as acronyms:

In[5]:=
ResourceFunction["FromCamelCase"]["APIFunction", "KnownWords" -> {"API"}]
Out[5]=

"KnownWords" should match the same case:

In[6]:=
ResourceFunction["FromCamelCase"]["APIFunctionapi", "KnownWords" -> {"API"}]
Out[6]=

But if IgnoreCase is used, "KnownWords" will match in any case but will return the capitalization given in "KnownWords":

In[7]:=
ResourceFunction["FromCamelCase"]["APIFunctionapi", "KnownWords" -> {"APi"}, IgnoreCase -> True]
Out[7]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

Related Resources

License Information