在R编程中将每个单词的第一个字母转换为大写 – str_to_title()函数
R语言中的str_to_title()
函数用于将字符串的每个单词的第一个字母转换为大写,其余字母转换为小写。
Note: This function uses 'stringr' library.
Syntax: str_to_title(string)
Parameter:
string: string to be converted
示例 1:
# R Program to illustrate
# the use of str_to_title function
# Loading Library
library(stringr)
# Creating a string
str <- "geeks for geeks"
# Calling str_to_title() function
str_to_title(str)
输出:
[1] "Geeks For Geeks"
示例 2:
# R Program to illustrate
# the use of str_to_title function
# Loading Library
library(stringr)
# Creating a string
str <- "GEEKS FOR GEEKS"
# Calling str_to_title() function
str_to_title(str)
输出:
[1] "Geeks For Geeks"