Thanks Erik for you reply. You have pointed correctly I want to remove the "space" at the 1st place (if any). In the mean time I have looked into the function sub() and there seems to be one example that mimics my problem :
> str <- '   Now is the time      '> sub('[[:space:]]+$', '', str)[1] "   Now is the time"

However it removes the space if it is at the last position. I have tried with different combinations like "sub('[[:space:]]-$', '', str)", "sub('$+[[:space:]]+$', '', str)" etc, none is working if space is at the 1st position.
What would be the correct approach?
Thanks,
--- On Sat, 6/12/10, Erik Iverson <eriki@ccbr.umn.edu> wrote:

From: Erik Iverson <eriki@ccbr.umn.edu>
Subject: Re: [R] Handling character string
To: "Megh Dal" <megh700004@yahoo.com>
Cc: r-help@stat.math.ethz.ch
Date: Saturday, June 12, 2010, 2:36 AM



Megh Dal wrote:
> Dear all, Is there any R function to say these 2 character strings
> "temp"  and " temp" are actually same? If I type following code R
> says there are indeed different :
>> "temp"  == " temp"[1] FALSE

You don't say how you're defining "same", but it definitely requires more explanation, since they are not the same.  Why should those two strings be the same in your mind?  Do you want to remove leading white space, all white space, just one space, etc?

You might find the examples in ?sub useful.





      
	[[alternative HTML version deleted]]

