r - 在 R 中拆分 CamelCase

标签 r split camelcasing

有没有办法在 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/

相关文章:

Ubuntu 安装上的 R BayesVarSel

R:unequi join 与合并功能

java - 如何将首字母缩写词与其在字符串中的含义分开

python - 拆分或替换 - 去掉两个字符串之间和周围的撇号和逗号

java - 将逗号分隔的字符串转换为整数数组的最佳方法

python - 将蛇形大小写的大写字母保留为驼峰大小写

r - 无法使用 read.zoo 读取

r - 将点图与 ggplot 连接起来。与 geom_line 连接

c# - 避免特定方法的 CamelCasePropertyNamesContractResolver

python - 将 pandas 列名称从蛇形命名法转换为驼峰式命名法