String question

Dennis Gurnick Dennis.Gurnick at pandorax.be
Tue Sep 12 15:08:55 CEST 2000


Yes, the 'slicing' is indeed what I was looking for.

Thank you.

D

"David Goodger" <dgoodger at bigfoot.com> wrote in message
news:B5E30E95.8E2B%dgoodger at bigfoot.com...
> on 2000-09-11 20:53, Dennis Gurnick (Dennis.Gurnick at pandorax.be) wrote:
> > Does Python(1.6) have built-in string functions for trimming or
extracting
> > portion of strings?
> >
> > I would like to do the following
> >
> > (prototype)
> > text = "here is some text"
> > seek = "is"
> > start = string.find( text, seek )
> > theWord = text.grabxxxxx( start, len(seek ) )
>
> You're trying to extract "is" from "here is some text"? You already have
> "is" in your example, so I'll assume your intent is more complex. Try
this:
>
>     >>> text = "here is some text"
>     >>> seek = "is"
>     >>> start = text.find(seek)         # you don't need 'string' in 1.6
>     >>> theWord = text[start : start + len(seek)]
>     >>> theWord
>     'is'
>
> Is the slicing operation (sequence[start:end]) what you're looking for?
> (Note that a slice includes the start, but does *not* include the end.)
>
> --
> David Goodger    dgoodger at bigfoot.com    Open-source projects:
>  - The Go Tools Project: http://gotools.sourceforge.net
>  (more to come!)
>





More information about the Python-list mailing list