Author Topic: Display a string in a list box  (Read 1636 times)

0 Members and 1 Guest are viewing this topic.

psuchewinner

  • Guest
Display a string in a list box
« on: August 09, 2007, 06:50:59 PM »
I need to turn the following string:
(P22353 P22160 P22798 P20945)

into a list that looks like this: (so that I can display it in a list box)
("P22353" "P22160" "P22798" "P20945")

Can anyone help?

As i understand it, I can only display a list in a list box and the only way to get a linebreak/feed is to group each line item on within separate quotation marks.

I want to send all of my dialog selections as defaults to the registry and I am not having luck writing the quoted text to the registry.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Display a string in a list box
« Reply #1 on: August 09, 2007, 09:38:32 PM »
I assume the first value is meant to be a string ..

Perhaps try something like this ;

(SETQ InitialValue '("P22353 P22160 P22798 P20945") )

(kdub:parsestring (car InitialValue) " ")

;;->> ("P22353" "P22160" "P22798" "P20945")

Code: [Select]
;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
(DEFUN kdub:parsestring (searchstring delimiter / templist index found)
    (SETQ index (VL-STRING-SEARCH delimiter searchstring))
    (WHILE index
        (SETQ templist     (CONS
                               (IF (= (SETQ found (SUBSTR searchstring 1 index)) delimiter)
                                      nil
                                      found
                               )
                               templist
                           )
              searchstring (SUBSTR searchstring (+ (STRLEN delimiter) index 1))
              index        (VL-STRING-SEARCH delimiter searchstring)
        )
    )
    (IF (> (STRLEN searchstring) 0)
        (SETQ templist (CONS searchstring templist))
    )
    (REVERSE templist)
)


;;;------------------------------------------------------------------
;;;------------------------------------------------------------------
;;;
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

psuchewinner

  • Guest
Re: Display a string in a list box
« Reply #2 on: August 10, 2007, 06:15:08 AM »
Thanks,
That look like it is exactly what I needed.  I will let you know after I get a chance to break it down and test it.  Gotta love this place!

psuchewinner

  • Guest
Re: Display a string in a list box
« Reply #3 on: August 10, 2007, 06:33:19 AM »
That is EXACTLY what I have been trying to do!  Can you explain how it works, add some comments to the code or something?  For some reason, I have an extremely hard time figuring out these types of functions.

 Thanks alot for the help.  I racked my brain yesterday for about 4 hours looking for this solution.

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Display a string in a list box
« Reply #4 on: August 10, 2007, 04:19:41 PM »
Hi,

It's a little too late, but I had some routine doing the same thing

(str2lst "a b c" " ") -> ("a" "b" "c")
(str2lst "1,2,3" ",") -> ("1" "2" "3")
(mapcar 'read (str2lst "1,2,3" ",")) -> (1 2 3)

Code: [Select]
(defun str2lst (str sep / pos)
  (if (setq pos (vl-string-position (ascii sep) str))
    (cons (substr str 1 pos)
  (str2lst (substr str (+ 2 pos)) sep)
    )
    (list str)
  )
)

and the opposite function

(lst2str '(1 2 3) ",") -> "1,2,3"
(lst2str '("a" "b" "c") " ") -> "a b c"

Code: [Select]
(defun lst2str (lst sep)
  (if (cadr lst)
    (strcat (vl-princ-to-string (car lst))
    sep
    (lst2str (cdr lst) sep)
    )
    (vl-princ-to-string (car lst))
  )
)
Speaking English as a French Frog