[Zope] String manipulation

Spicklemire, Jerry Jerry.Spicklemire@IFLYATA.COM
Tue, 26 Sep 2000 16:27:37 -0500


"how can I manage it to cut a string.

for example:

a string property (testtext) with 500 words.

but only want to give out 20 characters of tis text."

Python sequence slicing syntax can be done with DTML, like so:

<dtml-call "REQUEST.set('first_20_char', '_['some_long"string'][:20])">
<dtml-var first_20_char>

wher the '[:20]' means from the begining of the string, through the 20th
"slice". 
One thing to be aware of is that the positions start counting at 0, and are
best thought of as falling "between" the individual characters, like so:

	 a b c d e f g
	0 1 2 3 4 5 6 7

So the 20th position ('slice') is just past the 19th character, if the first
character is counted as 0.