[Zope] splitting strings ??

Jens Vagelpohl tommymi@concentric.net
Thu, 6 Jan 2000 07:39:00 -0500


hi geir,

i assume you're referring to the last element of the split-up string, not
the last character, right?

if i remember right from those great o'reilly books about python the last
element in a list (which is what you get from a split operation) can be
referred to by <mylistname>[-1], so your example would look like:

<dtml-if expr="_.string.split(_['REMOTE_ADDR'],'.')[-1] == '71'">

this works because you can count up from the first element ([0], [1] etc) or
down from the last ([-1], [-2]) by using negative indexes.

jens



> -----Original Message-----
> From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Geir
> B Hansen
> Sent: Thursday, January 06, 2000 06:01
> To: zope@zope.org
> Subject: [Zope] splitting strings ??
>
>
>
> i'm not very knowledgeable in the ways of python, but i've found out
> how to split strings by separators :
> for example :
> <dtml-if expr="_.string.split(_['REMOTE_ADDR'],'.')[1] == '71'">etc...
>
> how do i reference the *last* character of a string, not using any
> separators ??
>
> --
> Geir B Hansen
> web-developer/designer
> geirh@funcom.com
> http://www.funcom.com