How to convert a string to camelcase in Google Spreadsheet formula
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 REPLACE
ing 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)))®EXREPLACE(PROPER(TRIM(A1)),"(\w|\s)(\w*)","$2")
To do this the following formula works (where A3
is the cell)
tl;dr:
=IF(IFERROR(FIND(" ",A3)), CONCAT(SUBSTITUTE(LEFT(LOWER(A3), FIND(" ", A3)), " ", ""), SUBSTITUTE(PROPER(SUBSTITUTE(A3, LEFT(A3, FIND(" ", A3)), "")), " ", "")), LOWER(A3))
Annotated:
=IF( // if a single word
IFERROR( // test if NOT an error
FIND( // looking for a space
" ",
A3
)
),
CONCAT( // concat the first word with the rest
SUBSTITUTE( // remove the space
LEFT( // left of the find
LOWER( // lowercase the string
A3
),
FIND( // find the space in the string
" ",
A3
)
),
" ",
""
),
SUBSTITUTE( // remove spaces
PROPER( // convert string to capitals
SUBSTITUTE( // remove first word
A3,
LEFT( // left of the find
A3,
FIND( // find first space
" ",
A3
)
),
""
)
),
" ",
""
)
),
LOWER( // lowercase rest of the word
A3
)
)
This should work:
=JOIN("",ArrayFormula(UPPER(LEFT(SPLIT(A3," ")))&LOWER(MID(SPLIT(A3," "),2,500))))
or to be more precise:
=JOIN("",ArrayFormula(UPPER(LEFT(SPLIT(A3," ")))&LOWER(REGEXEXTRACT(SPLIT(A3," "),".(.*)"))))