Re: [R] Handling character string

From: jim holtman <jholtman_at_gmail.com>
Date: Sat, 12 Jun 2010 17:55:58 -0400

^[[:space:]]* indicates that you want to match as many (zero or more) spaces at the beginning of the string. The '^' anchors the match at the beginning. [[:space:]]*$ says to match as many (zero or more that is what "*" asks for) at the end of the string; "$" anchors the search at the end of the string.

On Sat, Jun 12, 2010 at 2:03 PM, Megh Dal <megh700004_at_yahoo.com> wrote:

> Thanks Jim for this reply. This is the way what I was looking for.
> However would you please explain me the meaning of ^[[:space:]]*"
> or '[[:space:]]+$'? When should I use "^" or "*" or "+$"?
>
> Thanks for your time.
>
> --- On *Sat, 6/12/10, jim holtman <jholtman_at_gmail.com>* wrote:
>
>
> From: jim holtman <jholtman_at_gmail.com>
>
> Subject: Re: [R] Handling character string
> To: "Megh Dal" <megh700004_at_yahoo.com>
> Cc: "Erik Iverson" <eriki_at_ccbr.umn.edu>, r-help_at_stat.math.ethz.ch
> Date: Saturday, June 12, 2010, 10:18 PM
>
>
> This is probably what you want:
>
> > sub("^[[:space:]]*", "", " Now is the time")
> [1] "Now is the time"
> >
>
> You need to anchor it at the beginning with '^'
>
> On Sat, Jun 12, 2010 at 10:29 AM, Megh Dal <megh700004@yahoo.com<http://mc/compose?to=megh700004@yahoo.com>>
> wrote:
> > 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<http://mc/compose?to=eriki@ccbr.umn.edu>>
> wrote:
> >
> > From: Erik Iverson <eriki@ccbr.umn.edu<http://mc/compose?to=eriki@ccbr.umn.edu>
> >
> > Subject: Re: [R] Handling character string
> > To: "Megh Dal" <megh700004@yahoo.com<http://mc/compose?to=megh700004@yahoo.com>
> >
> > Cc: r-help@stat.math.ethz.ch<http://mc/compose?to=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]]
> >
> >
> > ______________________________________________
> > R-help@r-project.org <http://mc/compose?to=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<http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>
>
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
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.
Received on Sat 12 Jun 2010 - 21:58:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Jun 2010 - 23:20:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive