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! ---------------------- Andy Gates, Learning and Research Technology Andy.Gates@bristol.ac.uk - ICQ#74362415
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
on Tuesday, June 27, 2000 Andy Gates wrote : AG> Simple stuff from the simple people today: string manipulation. AG> I have a string variable which has various chunks delimited by double AG> tildes ~~. In order to do what I need to do, I need to extract the AG> section of the string after the last double-tilde, so that AG> "fred~~bloggs" returns "bloggs" AG> "fred" returns "fred" AG> "fred~~bloggs~aardvark" returns "aardvark" AG> I can see that rfind is the thing I need to use, but as usual (gah! AG> newbie!) I'm stuck on the syntax. Help! try something like : <dtml-var expr="_.string.split('fred~~bloggs','~~')[-1]"> this is documented at http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.4.4.2.3.html - but not very newbie-friendly took me a long time to figure out how to use :-) -- Geir Bækholt web-developer/designer geirh@funcom.com http://www.funcom.com
Message-ID: <EXECMAIL.1000627140919.R@kosh.bris.ac.uk> Priority: NORMAL X-Mailer: Execmail for Win32 5.1 Build (9) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii"
<dtml-var expr="_.string.split('fred~~bloggs','~~')[-1]">
this is documented at http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.4.4.2.3.html - but not very newbie-friendly
Perfecto! Thank you! AndyG
----- Original Message ----- From: Andy Gates <Andy.Gates@bristol.ac.uk> To: <zope@zope.org> Sent: Tuesday, June 27, 2000 1:39 PM Subject: [Zope] Newbie: String work
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!
Maybe is a little strange , but should work (I hope:) <dtml-let a="'abc~~ABC~~s'"> <dtml-var "a[((_.string.rfind(a,'~~')+1) or-1 )+1:]"> </dtml-let> Or maybe is better to use split, is more readable <dtml-var "_.string.split(a,'~~')[-1]"> PM
Hello Andy the syntax should be let string = "fred~~bloggs~aardvark" _.string.split(string,'~~')[-1] i.e. <dtml-var "_.string.split(string,'~~')[-1]"> Should work. In python, it's the same thing. ----- Original Message ----- From: Andy Gates <Andy.Gates@bristol.ac.uk> To: <zope@zope.org> Sent: Tuesday, June 27, 2000 12:39 PM Subject: [Zope] Newbie: String work
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! ---------------------- Andy Gates, Learning and Research Technology Andy.Gates@bristol.ac.uk - ICQ#74362415
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (5)
-
Andy Gates -
Geir B�kholt -
Marcel Preda -
peter be -
Rik Hoekstra