[Zope] How to check if a string contains some characters??

Spicklemire, Jerry Jerry.Spicklemire@IFLYATA.COM
Mon, 12 Mar 2001 13:27:51 -0500


Casey Duncan corrected:

> There is no dtml-while tag.

Sure enough, all the discussions about <dtml-while> that I recalled 
reading turned out to be explanations of why it doesn't exist.

Thanks again to the NIP Ltd. folks for making this easy to verify, 
with their handy Zope Mail List search. Now if I can only find a 
way to force my self to do the searching FIRST! Oh well, 11.75 
months to live this down before the next Python conference.

> You cannot iterate a string with dtml-in 8^(

This is also true. When the need arises to loop over a string, 
a Python coder would convert the string to a list or tuple. 

So, you could do this :

<dtml-call "REQUEST.set('string_name', 
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-_')">

<dtml-call "REQUEST.set('char_list', [])">

<dtml-in "_.range(_.len(string_name))">

 <dtml-let s_i=sequence-index
   char_single="string_name[s_i]">

  <dtml-call "char_list.append(char_single)">

 </dtml-let>
</dtml-in>

to stuff characters into a list, either statically, as above, 
or dynamically, for an arbitrary string. 

This just goes to show why the first instinct ("just kick out some 
<dtml>") is often not the best solution.

{snip an excellent example of a simple implementation in <dtml>}

> The performance of this would be much less than using an external python
> method and regular expressions however.

I'm sure RegEx is fast, but I was shooting for simple, and clear. 
Next time I'll shoot for existent, and possible too . . .

Thanks for clearing it up,
Jerry S.