gpt4 book ai didi

r - 第一个字母改为大写

转载 作者:行者123 更新时间:2023-12-02 02:13:07 25 4
gpt4 key购买 nike

是否有其他版本可以将每个字符串的第一个字母设为大写,并且对于 flac perl 也使用 FALSE?

name<-"hallo"
gsub("(^[[:alpha:]])", "\\U\\1", name, perl=TRUE)

最佳答案

您可以尝试以下方法:

name<-"hallo"
paste(toupper(substr(name, 1, 1)), substr(name, 2, nchar(name)), sep="")

或者另一种方法是具有如下功能:

firstup <- function(x) {
substr(x, 1, 1) <- toupper(substr(x, 1, 1))
x
}

示例:

firstup("abcd")
## [1] Abcd

firstup(c("hello", "world"))
## [1] "Hello" "World"

关于r - 第一个字母改为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18509527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com