extract text from a string
Tim Williams
tim at tdw.net
Thu Nov 9 10:57:53 EST 2006
On 9 Nov 2006 07:45:25 -0800, boris.smirnov at gmail.com
<boris.smirnov at gmail.com> wrote:
>
> I have a string containing: "+abc_cde.fgh_jkl\n" and what I need to
> become is "abc_cde.fgh_jkl". Could anybody be so kind and write me a
> code of how to extract this text from that string?
>
for that particular string
>>> "+abc_cde.fgh_jkl\n"[1:-1]
'abc_cde.fgh_jkl'
>>> "+abc_cde.fgh_jkl\n".strip()[1:]
'abc_cde.fgh_jkl'
>>> "+abc_cde.fgh_jkl\n"[1:].strip()
'abc_cde.fgh_jkl'
>>> "+abc_cde.fgh_jkl\n"[1:].strip().replace('+','')
'abc_cde.fgh_jkl'
>>> "+abc_cde.fgh_jkl\n"[1:].replace('\n','').replace('+','')
'abc_cde.fgh_jkl'
I'm sure there are other ways too !!
HTH :)
More information about the Python-list
mailing list