[Zope] Extracting a part of a string

Casey Duncan cduncan@kaivo.com
Fri, 29 Jun 2001 08:49:29 -0600


sbergmann@weblog.de wrote:
>=20
> Hello Zopers,
>=20
> I have the following problem:
>=20
> I have a string from a database and want to delete a part from the
> string and write it back to the database.
>=20
> An example:
>=20
> a =3D ' some words ( another words)'
> I want to extract now everything without the brackets themselves anth
> the words in the brackets.
> That should be the result.
>=20
> a =3D 'some words'
>=20
> How can I do that. With the string-module and "find"  I can get the
> index where the brackets begin. But there is no function to get the
> string from index 0 to the result  index of "find".
>=20
> Is there another way to do this?
>=20
> I=B4m sure that somebody has a solution for me.
>=20
> Steffen

You might try:

_.string.split(a,'(')[0]

Which should still work even if the string has no "(" (it will return
the whole thing then).

hth,
--=20
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>