大写的第一个字母 [英] First letter to upper case

查看:67
本文介绍了大写的第一个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a other version to make the first letter of each string capital and also with FALSE for flac perl?

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

推荐答案

你可以试试:

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

或者另一种方法是拥有一个类似的功能:

Or another way is to have a function like:

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

示例:

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

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

这篇关于大写的第一个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆