Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First letter to upper case

Tags:

string

r

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) 
like image 910
Klaus Avatar asked Aug 29 '13 11:08

Klaus


People also ask

Which case capitalized the first letter?

CamelCase Words are written without spaces, and the first letter of each word is capitalized. Also called Upper Camel Case or Pascal Casing.

What is initial upper case?

Noun. initial caps (uncountable) (journalism, typography) A variant of title case in which every word begins with an upper-case letter and its other letters are lower-case.

Which function returns first letter of word in upper case?

The toUpperCase() method converts the string to uppercase.


Video Answer


2 Answers

You can try something like:

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 } 

Examples:

firstup("abcd") ## [1] Abcd  firstup(c("hello", "world")) ## [1] "Hello" "World" 
like image 152
alko989 Avatar answered Oct 02 '22 22:10

alko989


As pointed out in the comment, it is now possible to do: stringr::str_to_title("iwejofwe asdFf FFFF")

stringr uses stringi under the hood which takes care of complex internationalization, unicode, etc., you can do: stri_trans_totitle("kaCk, DSJAIDO, Sasdd.", opts_brkiter = stri_opts_brkiter(type = "sentence"))

There is a C or C++ library underneath stringi.

like image 43
Jack Wasey Avatar answered Oct 02 '22 23:10

Jack Wasey