[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating string from list of strings

From: Joe Casadonte
Subject: Re: Creating string from list of strings
Date: 14 Oct 2002 10:00:07 -0400
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2

On Mon, 14 Oct 2002, Bill Wohler wrote:

>   I wasn't able to figure out from the Elisp manual how to turn a
>   list of strings into a single string. For example, how does one
>   print the following list of strings?
>     (setq list-of-strings '("foo" "bar"))
>     (message (perform-magic-with list-of-strings))
>   While the following works, it seems that there should be a
>   one-liner to do this already:
>     (defvar my-string)
>     (while list-of-strings
>       (setq my-string (concat my-string (car list-of-strings)))
>       (setq list-of-strings (cdr list-of-strings)))
>     (message (my-string))

Some folks have already showed you what to do to get a simple concat
like you had asked for.  Here's something I whipped up to get a
perl-like join command.

(defun my-perl-join (join-string elements)
  "[Internal] Function to mimic Perl's join() function.

JOIN-STRING is the string to use to join them together.
ELEMENTS is a list of what to join.


  \(my-perl-join \"/\" (list \"some\" \"file\" \"path\")

would result in the string:


Note that no leading slash is put in; JOIN-STRING is only put in
between the joined elements."
  (let (rc active subsequent-pass)
        (while elements
          (setq active (car elements))
          (setq elements (cdr elements))

          (if (not subsequent-pass)
                  (setq subsequent-pass t)
                (setq rc (concat rc join-string))

          (setq rc (concat rc active)))


Joe Casadonte

         Llama Fresh Farms =>
   Gay Media Resource List =>
            Perl for Win32 =>
               Emacs Stuff =>
          Music CD Trading =>
                       Live Free, that's the message!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]