Results 1 to 7 of 7

Thread: convert String to List

  1. #1
    Active Member
    Join Date
    2005-02
    Posts
    95

    Default convert String to List

    I have a problem with a list. I want to convert string to list.

    there is three nos. of data first member size, second its part no. and third is length of that member.

    "L50X50X6 45 4000" or

    "L100X100X8 92 2483"


    I want to convert it to list. like... (L50X50X6 45 4000) OR (L 100X100X8 92 2483).

    can it is possible.

  2. #2
    I could stop if I wanted to kpblc2000's Avatar
    Join Date
    2006-09
    Posts
    211

    Default Re: convert String to List

    Look at the http://forums.augi.com/showthread.php?t=48298
    function _kpblc-string-parser
    Use AUTOCAD / ADT / AA 2006 / 2008 / 2010
    All i say is only my opinion
    I'm watching you! Your

  3. #3

    Default Re: convert String to List

    Try the following and see if it will work for you.
    Terry
    Code:
    ;-------------------------------------------------------------------------------
    ; WordList - Returns a list of words in a sentence
    ; Arguments: 1
    ;   Sentence$ = String to convert into a list strings
    ; Syntax: (WordList "Words in a sentence") = (list "Words" "in" "a" "sentence")
    ; Returns: List of words or strings that were seperated by spaces in a sentence
    ;-------------------------------------------------------------------------------
    (defun WordList (Sentence$ / Cnt# Item$ Mid$ Num# ReturnList@)
      (setq Cnt# 1 Num# 1)
      (repeat (strlen Sentence$)
        (setq Mid$ (substr Sentence$ Cnt# 1))
        (if (= Mid$ " ")
          (progn
            (setq Item$ (substr Sentence$ Num# (- Cnt# Num#)))
            (if (/= Item$ "")
              (setq ReturnList@ (append ReturnList@ (list Item$)))
            );if
            (setq Num# (1+ Cnt#))
          );progn
        );if
        (setq Cnt# (1+ Cnt#))
      );repeat
      (if (not ReturnList@)
        (setq ReturnList@ (list Sentence$))
        (if (/= (substr Sentence$ Num#) "")
          (setq ReturnList@ (append ReturnList@ (list (substr Sentence$ Num#))))
        );if
      );if
      ReturnList@
    );defun WordList

  4. #4
    Active Member ElpanovEvgeniy's Avatar
    Join Date
    2006-09
    Location
    Russia, Moscow
    Posts
    54

    Default Re: convert String to List

    Code:
    (defun str-lst (s p)
     (if (vl-string-search p s)
      (str-lst (vl-string-subst "\"\"" p s) p)
      (read (strcat "(\"" s "\")"))
     ) ;_  if
    ) ;_  defun
    
    (str-lst "L50X50X6 45 4000" " ")
    (str-lst "L100X100X8 92 2483" " ")
    (str-lst "L50X50X6;;;45;;;4000" ";;;")
    (str-lst "L100X100X8-=Divider=-92-=Divider=-2483" "-=Divider=-")

  5. #5
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2002-12
    Location
    Brandon, Florida
    Posts
    687

    Default Re: convert String to List

    Nice code Evgeniy.

  6. #6
    Past Vice President peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu Hawaii
    Posts
    574

    Default Re: convert String to List

    This is my generalized solution for converting strings into lists, I use it with csv files.

    (csvstringtolist "this is my test" " ") returns '("this" "is" "my" "list)

    or or the comma separated

    (csvstringtolist "this,is,my,test" ",") returns '("this" "is" "my" "list)

    It also works for multiple letter delimiters like "**" or "\\"

    Peter

    Code:
    (defun CSVStringToList  (strText strChar / intPosition lstStrings)
     (while (setq intPosition (vl-string-search strChar strText 0))
      (setq lstStrings  (cons (substr strText 1 intPosition) lstStrings)
            strText     (substr strText (+ intPosition 1 (strlen strChar)))
      )
     )
     (if lstStrings
      (reverse (cons strText lstStrings))
      (list strText)
     )
    )

  7. #7
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2002-12
    Location
    Brandon, Florida
    Posts
    687

    Default Re: convert String to List

    Similar to the one I have.
    Code:
    ;  parser by CAB multi char delim 
    (defun sparser (str delim / dlen ptr lst)
      (setq dlen (1+ (strlen delim)))
      (while (setq ptr (vl-string-search delim str))
        (setq lst (cons (substr str 1 ptr) lst))
        (setq str (substr str (+ ptr dlen)))
      )
      (reverse(cons str lst))
    )

Similar Threads

  1. Convert string to variable
    By davila.vanegas in forum AutoLISP
    Replies: 8
    Last Post: 2010-07-06, 12:42 PM
  2. Need to convert a string into a list.
    By Mike_R in forum AutoLISP
    Replies: 2
    Last Post: 2008-02-04, 05:56 PM
  3. convert a list to a string
    By ccowgill in forum AutoLISP
    Replies: 3
    Last Post: 2006-09-21, 10:18 AM
  4. Convert SUBR name in to a string
    By kennet.sjoberg in forum AutoLISP
    Replies: 8
    Last Post: 2005-08-22, 06:16 PM
  5. convert string to List
    By pnorman in forum AutoLISP
    Replies: 2
    Last Post: 2005-04-25, 03:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •