有没有办法在 R 中拆分驼峰式字符串?
我尝试过:
string.to.split = "thisIsSomeCamelCase"
unlist(strsplit(string.to.split, split="[A-Z]") )
# [1] "this" "s" "ome" "amel" "ase"
最佳答案
string.to.split = "thisIsSomeCamelCase"
gsub("([A-Z])", " \\1", string.to.split)
# [1] "this Is Some Camel Case"
strsplit(gsub("([A-Z])", " \\1", string.to.split), " ")
# [[1]]
# [1] "this" "Is" "Some" "Camel" "Case"
看看 Ramnath 和我的,我可以说我最初的印象是,这是一个未具体说明的问题得到了支持。
并为 Tommy 和 Ramanth 的指出点赞
[:upper:]
strsplit(gsub("([[:upper:]])", " \\1", string.to.split), " ")
# [[1]]
# [1] "this" "Is" "Some" "Camel" "Case"
关于r - 在 R 中拆分 CamelCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8406974/