Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a string to camelcase in Google Spreadsheet formula

Trying to create a formula to turn a string of words separated by spaces into camelcase

like image 807
Ryan Schumacher Avatar asked Apr 13 '17 18:04

Ryan Schumacher


People also ask

What is the shortcut key for Change case in Google Sheets?

It requires only one argument: a text where you want to change the case or a reference to a cell with that text. Once I enter the formula, Google Sheets offers to copy it down for me and capitalize the first letters in all cells: You can either press Ctrl+Enter or click the tick icon to allow spreadsheets to do that.


1 Answers

Much smaller version:

=SUBSTITUTE(PROPER(TRIM(A1))," ","")

We just use PROPER to upper case and TRIM and SUBSTITUTE to remove spaces.

If we want lowerCamelCase,

By just REPLACEing the first character with lower case, We have:

=REPLACE(SUBSTITUTE(PROPER(TRIM(A1))," ",),1,1,LEFT(LOWER(TRIM(A1))))

Using REGEX:

=REGEXREPLACE(REGEXREPLACE(PROPER(A1),"\s*",),"^(\w)",LEFT(LOWER(TRIM(A1))))

=LOWER(LEFT(TRIM(A1)))&REGEXREPLACE(PROPER(TRIM(A1)),"(\w|\s)(\w*)","$2")
like image 132
TheMaster Avatar answered Oct 03 '22 06:10

TheMaster