Skip to content
Prev 32047 / 398506 Next

Is there a simple method of changing text into 'Proper Ca se'

Thank you for the help. As a result I have written two functions.

SentCase <- function(InputString){
 InputString <-
paste(toupper(substring(InputString,1,1)),tolower(substring(InputString,2)),
sep="")
}

ProperCase <- function(InputString){
sapply(lapply(strsplit(InputString," "), SentCase), paste, collapse=" ")
}

        > cat(SentCase("this little string"))
        This little string> 
        > cat(ProperCase("this little string"))
        This Little String> 

-----Original Message-----
From: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de] 
Sent: Wednesday, 14 May 2003 2:40 PM
To: Mulholland, Tom
Cc: 'Spencer Graves'; (r-help at stat.math.ethz.ch)
Subject: Re: [R] Is there a simple method of changing text into 'Proper Ca
se'
Mulholland, Tom wrote:
Perl experts might do it differently, but the "R way" seems to be

  substring(x, 1, 1) <- toupper(substring(x, 1, 1))
  substring(x, 2) <- tolower(substring(x, 2))

Uwe Ligges