Hey everybody! I have a problem with triming a string. I can get rid of the blank space in front and at the back of a string and even trim a string at the back. But I don't know how to do it in the front. For Example: I have a string "Blackberry" and i want to delete the first 5 characters to get just "berry". Tnx for your help -- View this message in context: http://old.nabble.com/How-to-trim-the-front-of-a-string--tp26459983p26459983.html Sent from the R help mailing list archive at Nabble.com.
Hi Ivansek, Here is a suggestion using substr():> x <- 'Blackberry' > substr(x, 6, nchar(x))[1] "berry" HTH, Jorge On Sat, Nov 21, 2009 at 4:05 PM, rok90 <> wrote:> > Hey everybody! > > I have a problem with triming a string. I can get rid of the blank space in > front and at the back of a string and even trim a string at the back. But I > don't know how to do it in the front. > > For Example: I have a string "Blackberry" and i want to delete the first 5 > characters to get just "berry". > > Tnx for your help > -- > View this message in context: > http://old.nabble.com/How-to-trim-the-front-of-a-string--tp26459983p26459983.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Here are three ways:> substring("blackberry", 6)[1] "berry"> sub("^black", "", "blackberry")[1] "berry"> sub(".{5}", "", "blackberry")[1] "berry" On Sat, Nov 21, 2009 at 4:05 PM, rok90 <ivansek.labris at gmail.com> wrote:> > Hey everybody! > > I have a problem with triming a string. I can get rid of the blank space in > front and at the back of a string and even trim a string at the back. But I > don't know how to do it in the front. > > For Example: I have a string "Blackberry" and i want to delete the first 5 > characters to get just "berry". > > Tnx for your help > -- > View this message in context: http://old.nabble.com/How-to-trim-the-front-of-a-string--tp26459983p26459983.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >