How to convert string to camelcase in Google Spreadsheet formula
4 answers
Much smaller version:
=SUBSTITUTE(PROPER(TRIM(C8))," ","")
We just use PROPER
for uppercase and TRIM
and SUBSTITUTE
to remove spaces.
EDIT:
It seems that the OP specifically wanted lowerCamelCase, just REPLACE
with the first lowercase character, 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))))
+7
source to share
To do this, use the following formula (where A3
is a 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
)
)
+4
source to share