[Zope] Newbie: String work
Rik Hoekstra
rik.hoekstra@inghist.nl
Tue, 27 Jun 2000 14:01:03 +0200
Andy Gates wrote:
>
> Simple stuff from the simple people today: string manipulation.
>
> I have a string variable which has various chunks delimited by double
> tildes ~~. In order to do what I need to do, I need to extract the
> section of the string after the last double-tilde, so that
>
> "fred~~bloggs" returns "bloggs"
> "fred" returns "fred"
> "fred~~bloggs~aardvark" returns "aardvark"
>
> I can see that rfind is the thing I need to use, but as usual (gah!
> newbie!) I'm stuck on the syntax. Help!
what about (in convoluted DTML very lightly tested):
<dtml-call "REQUEST.set('instr', <yourstring>)">
<dtml-call "REQUEST.set('ix', _.string.rfind(instr,'~~'))">
<dtml-var "instr[ix]">
If you want the part after the ~~, you'll have to add +2 to the string
index, like instr[ix+2:]. Making this fit for the 'fred' case is left as
an exercise for the reader ;-=)
hth
Rik