尝试创建一个公式,将由空格分隔的单词字符串转换为驼峰式。
更小的版本:
=SUBSTITUTE(PROPER(TRIM(A1))," ","")
我们只需使用PROPER
将字母大写,再用TRIM
和SUBSTITUTE
去除空格。
如果我们想要lowerCamelCase,
只需使用REPLACE
替换第一个字符为小写,就可以得到:
=REPLACE(SUBSTITUTE(PROPER(TRIM(A1))," ",),1,1,LEFT(LOWER(TRIM(A1))))
使用正则表达式:
=REGEXREPLACE(REGEXREPLACE(PROPER(A1),"\s*",),"^(\w)",LEFT(LOWER(TRIM(A1))))
=LOWER(LEFT(TRIM(A1)))®EXREPLACE(PROPER(TRIM(A1)),"(\w|\s)(\w*)","$2")
SomeWordsHere
而不是someWordsHere
。如果我错了,请纠正我。 - Ryan Schumacher=REPLACE(SUBSTITUTE(PROPER(TRIM(A3))," ",""), 1,1,LOWER(LEFT(TRIM(A3))))
这将给出 someWordsHere
的小驼峰式命名法。 - TheMasterTRIM
的保险措施,这个公式看起来会小得多。 - TheMaster这应该可以工作:
=JOIN("",ArrayFormula(UPPER(LEFT(SPLIT(A3," ")))&LOWER(MID(SPLIT(A3," "),2,500))))
=JOIN("",ArrayFormula(UPPER(LEFT(SPLIT(A3," ")))&LOWER(REGEXEXTRACT(SPLIT(A3," "),".(.*)"))))
要完成这个任务,可以使用以下公式(其中A3
是单元格)
简而言之:
=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
)
)
created_at => createdAt
)。=REPLACE(SUBSTITUTE(PROPER(A5), "_", ""), 1, 1, LOWER(LEFT(A5, 1)))
上述公式为:
大部分工作都是使用 PROPER 函数完成的,除了最后一部分将第一个字符替换为其小写版本。