A more elegant way would be: myString<-"1 2 3 4 5" myString<-paste(unlist(strsplit(myString," ")),collapse="") The output will be "12345" Regards, Som Shekhar