Author Topic: Make strange string in to a list?  (Read 10779 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Make strange string in to a list?
« Reply #15 on: April 01, 2010, 12:51:35 PM »
Thought that might be a concern.  Oh well.  But in the interest of cat skinning.

Code: [Select]
((lambda ( s ) (substr s 1 (1- (strlen s))))(apply 'strcat (mapcar (function (lambda ( a ) (strcat a ","))) '("a" "b" "c"))))
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Make strange string in to a list?
« Reply #16 on: April 01, 2010, 12:52:45 PM »
Thought that might be a concern.  Oh well.  But in the interest of cat skinning.

Code: [Select]
((lambda ( s ) (substr s 1 (1- (strlen s))))(apply 'strcat (mapcar (function (lambda ( a ) (strcat a ","))) '("a" "b" "c"))))
Nice.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Make strange string in to a list?
« Reply #17 on: April 01, 2010, 12:57:46 PM »
Code: [Select]
(substr (apply 'strcat (mapcar (function (lambda ( a ) (strcat "," a))) '("a" "b" "c"))) 2)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make strange string in to a list?
« Reply #18 on: April 01, 2010, 01:02:47 PM »
Code: [Select]
(mapcar (function (lambda(x) (setq str (cond (str (strcat str "," x))(x))))) strlist)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Make strange string in to a list?
« Reply #19 on: April 01, 2010, 01:05:15 PM »
Well now I fell dumb. LoL
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Make strange string in to a list?
« Reply #20 on: April 01, 2010, 01:57:15 PM »
Code: [Select]
(apply 'strcat (mapcar 'strcat '("a" "b" "c") '("," "," "")))

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Make strange string in to a list?
« Reply #21 on: April 01, 2010, 02:44:06 PM »
Code: [Select]
(defun Str-Make (lst del / str x)
  (setq str  (car lst))
  (foreach x (cdr lst) (setq str (strcat str del x)))
str)

Code: [Select]
(defun Str-Make (lst del / str)
  (setq str (car lst))
  (while (setq lst (cdr lst)) (setq str (strcat str del (car lst))))
str)
« Last Edit: April 01, 2010, 02:52:13 PM by Lee Mac »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Make strange string in to a list?
« Reply #22 on: April 01, 2010, 02:50:10 PM »
Code: [Select]
(defun Str-Make (lst del / str x)
    (setq str  (car lst))
    (foreach x (cdr lst) (setq str (strcat str del x)))
  str)

Code: [Select]
(defun Str-Make (lst del / str)
  (setq str (car lst))
  (while (setq lst (cdr lst)) (setq str (strcat str del (car lst))))
  str)
Very cool Lee! And to think, I was pretty happy with my recursive one.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Make strange string in to a list?
« Reply #23 on: April 01, 2010, 02:51:41 PM »
Very cool Lee! And to think, I was pretty happy with my recursive one.

Thanks Alan, just adding to the mix  8-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make strange string in to a list?
« Reply #24 on: April 01, 2010, 03:03:42 PM »
Just wrapped 8-)
Code: [Select]
(defun Str-Make (lst del / str)
  (mapcar (function (lambda(s) (setq str (if str (strcat str del s) s)))) lst)
  str
)
Code: [Select]
(defun Str-Make (lst del / str f)
  (apply 'strcat (mapcar (function (lambda (s) (setq f (if f (strcat del s) s)))) lst))
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

KewlToyZ

  • Guest
Re: Make strange string in to a list?
« Reply #25 on: April 01, 2010, 04:28:47 PM »
 :?

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Make strange string in to a list?
« Reply #26 on: April 01, 2010, 04:33:18 PM »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make strange string in to a list?
« Reply #27 on: April 01, 2010, 04:56:22 PM »
Looks like someone working on "String Theory" :evil:
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

jeff101217

  • Guest
Re: Make strange string in to a list?
« Reply #28 on: April 01, 2010, 09:20:31 PM »
Another  :-)

Code: [Select]
(defun StringStrip (str)
  ;; Lee Mac  ~  01.04.10

  (defun StringParser (str del)
    (if (setq pos (vl-string-search del str))
      (cons (substr str 1 pos)
            (StringParser (substr str (+ pos 1 (strlen del))) del))
      (list str)))

  (StringParser (vl-string-trim "*" str) "*"))

Code: [Select]
(StringStrip "*jsyq_g_list*G1*G2*G3*G4*G5*")
==> ("jsyq_g_list" "G1" "G2" "G3" "G4" "G5")

 :-D :lol: great!

jeff101217

  • Guest
Re: Make strange string in to a list?
« Reply #29 on: April 01, 2010, 09:29:11 PM »
thanks a lot every one , i think this problem is solved;and  i got some new thought . :-D