[phobos] Splitting words with delimiter

Andrei Alexandrescu andrei at erdani.com
Mon Aug 29 12:29:28 PDT 2011


joiner

Andrei

On 8/29/11 1:45 PM, unDEFER wrote:
> Hello!
> So as I understand that D tries to make really practical tasks more easy
> I want to ask about one often meeting task.
> If I want to print words with delimiter I can do it with 3 ways:
>
> 1)
> <print first word>
> foreach <other word>
> print ", " ~ <word>
> end for
>
> 2)
> foreach <all words>
> if (not first)
> print ", "
> print <word>
> end for
>
> 3)
> foreach <all words>
> print <word> ~ ", "
> end for
> if <list of words not empty>
> <delete last character>
>
> But sometimes there is other similar tasks which makes any from this
> approach very ugly.
> The simple example: putting array of strings to cells of tables on the
> pages. Each page is table with 5 rows and 2 columns. And print at the
> end of each page the "next" or "first" (for last page) button.
> I really don't remember details but in my anyfs-tools.sf.net I had many
> examples of this task and it was not connected with just printing.
>
> If there is any good methods to do any complex case of this task more
> beautiful with D?
> Thank you.
>


More information about the phobos mailing list