How to convert string to camelcase in Google Spreadsheet formula

Trying to create a formula to camelcase a string of whitespace-separated words

+5


source to share


4 answers


This should work:

=JOIN("",ArrayFormula(UPPER(LEFT(SPLIT(A3," ")))&LOWER(MID(SPLIT(A3," "),2,500))))



or rather:

=JOIN("",ArrayFormula(UPPER(LEFT(SPLIT(A3," ")))& LOWER(REGEXEXTRACT(SPLIT(A3," "),".(.*)"))))

+2


source


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 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


If the string of words you are trying to turn into camel case is contained in A1, the formula is very simple:

=MINUSCULE(REGEXREPLACE(A1, " ", "_"))

      

0


source







All Articles