List transformation

List transformation

Browning_Zed
Advocate Advocate
574 Views
3 Replies
Message 1 of 4

List transformation

Browning_Zed
Advocate
Advocate

Hello everyone,
This may be a simple task, but my knowledge is not enough to solve it.
How to get the string "\ nA \ nB \ nC \ nD" from the existing list '("A" "B" "C" "D")?

0 Likes
Accepted solutions (1)
575 Views
3 Replies
Replies (3)
Message 2 of 4

Moshe-A
Mentor
Mentor

@Browning_Zed ,

 

somting like this?  (un tested)

 

enjoy

moshe

 

 

(setq lst (mapcar
             '(lambda (s)
               (strcat "\\ n " s)
               )
            '("A" "B" "C" "D")
           )
)

 

Message 3 of 4

pbejse
Mentor
Mentor
Accepted solution

@Browning_Zed wrote:

Hello everyone,
This may be a simple task, but my knowledge is not enough to solve it.
How to get the string "\ nA \ nB \ nC \ nD" from the existing list '("A" "B" "C" "D")?


 

it depends, if you need just the "\" you have to use "\\"

 

(setq lst '("A" "B" "C" "D"))
(substr (apply 'strcat (mapcar '(lambda (s)
               (strcat " \\ n" s)
               ) lst )) 2)

 

 

but for newline "\n" this is enough

 

(setq lst '("A" "B" "C" "D"))
(substr (apply 'strcat (mapcar '(lambda (s)
               (strcat " \n" s)
               ) lst )) 2)

 

Sorry about that, my bad 

 

 

 

 

Message 4 of 4

Sea-Haven
Mentor
Mentor

An alternative method

 

(setq lst '("A" "B" "C" "D"))
(setq str "")
(foreach val lst
(setq str (strcat str " \n" val))
)