Function Repository Resource:

ToCamelCase

Source Notebook

Convert a string to lower camel case

Contributed by: Andrew Steinacher

ResourceFunction["ToCamelCase"][string]

converts string to lower camel case.

Details and Options

Camel case, also known as "camel caps" or "medial capitals," is a string without spaces where each word is capitalized, such as "johnSmith" or "JaneDoe".
Camel case is a naming convention frequently used for variable names in computer programming.
ResourceFunction["ToCamelCase"] converts strings to lower camel case (e.g. "johnSmith"). This is sometimes known as "dromedary case."
To create a string in upper camel case (e.g. "JaneDoe"), use Capitalize after ResourceFunction["ToCamelCase"]. This is sometimes known as "Pascal case."
The capitalized letters in a camel case string resemble the humps on a camel.

Examples

Basic Examples (1) 

Take a simple case and convert it to lower camel case:

In[1]:=
ResourceFunction["ToCamelCase"]["lower camel case"]
Out[1]=

Scope (1) 

Use Capitalize in conjunction with ToCamelCase to generate a string in upper camel case:

In[2]:=
Capitalize[ResourceFunction["ToCamelCase"]["upper camel case"]]
Out[2]=

Possible Issues (2) 

Only whitespace characters are removed, so symbols, punctuation and numbers remain in the resulting string:

In[3]:=
ResourceFunction["ToCamelCase"]["Sentence #1. Sentence #2."]
Out[3]=

Keep only letters:

In[4]:=
StringDelete["Sentence #1. Sentence #2.", _?(Not[LetterQ[#]] || Not[WhitespaceCharacter] &)]
Out[4]=

Special characters are left untouched:

In[5]:=
ResourceFunction["ToCamelCase"]["Käse"]
Out[5]=

Use RemoveDiacritics to normalize special characters to ASCII-friendly characters:

In[6]:=
ResourceFunction["ToCamelCase"][RemoveDiacritics["Käse"]]
Out[6]=

Publisher

Andrew Steinacher

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 2.0.0 – 08 March 2019
  • 1.0.0 – 25 February 2019

Related Resources

License Information