Author Topic: function to create a list out of strings  (Read 3083 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
function to create a list out of strings
« on: August 18, 2014, 04:04:09 PM »
sorry i have to ask this
there was a post here at one point that had a function to create a list of strings without assigning it to a variable.
im unable to find it in a serarch and for the life of me i dont even remember who make it but i do remember seeing it here.

would anyone happen to know what im refering to and would you have that link?
« Last Edit: August 21, 2014, 09:05:05 AM by andrew_nao »

Gasty

  • Newt
  • Posts: 90
Re: function to create a list of strings
« Reply #1 on: August 19, 2014, 01:25:28 AM »
Hi,

I'm not sure to understand, where are the strings? or where they come from?

Gaston Nunez


dgorsman

  • Water Moccasin
  • Posts: 2437
Re: function to create a list of strings
« Reply #2 on: August 19, 2014, 10:15:51 AM »
Do you mean, create several variable names in sequence ie. var1 var2 var3 ?
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

reltro

  • Guest
Re: function to create a list of strings
« Reply #3 on: August 19, 2014, 10:56:12 AM »
Hey...

Not sure what u mean...
maybe like this?

Code - Auto/Visual Lisp: [Select]
  1. (mapcar 'getstring '("Enter String 01: " "Enter String 02: " "Enter String 03: " "Enter String 04: "))

This piece of code collects 4 strings by asking the user to enter them...
The return is a list of the collected strings...

greets reltro

andrew_nao

  • Guest
Re: function to create a list of strings
« Reply #4 on: August 19, 2014, 02:44:18 PM »
thanks for everyones replies
i found the code in an old lisp test file that i had
sadly i dont know who wrote it to give the credit to.

here is the code tho if anyone has need. credit to "unknown"
Code: [Select]
(defun str2lst (str sep / pos)
  (if (setq pos (vl-string-search sep str))
    (cons (substr str 1 pos)
  (str2lst (substr str (+ (strlen sep) pos 1)) sep)
    )
    (list str)
  )
)

;useage: (str2lst var " ")

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: function to create a list of strings
« Reply #5 on: August 19, 2014, 03:03:22 PM »
Perhaps this was the droids thread you were looking for?

http://www.theswamp.org/index.php?topic=32845.0


Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1453
  • Marco
Re: function to create a list of strings
« Reply #6 on: August 19, 2014, 04:11:44 PM »
here is the code tho if anyone has need. credit to "unknown"
credit to gile (France).
http://www.theswamp.org/index.php?topic=22034.msg265916#msg265916

Another version:
Code: [Select]
; Function: ALE_String_ToList
;
; Version 1.00 - 01/2010
;
; Description:
;   convert a string into a list of strings
;
; Arguments:
;   InpStr = string [STR]
;   CarDlm = delimiter [STR] 1 character
;   TrueFl = if nil remove dupes delimiter
;
; Examples:
;  (ALE_String_ToList "aaa_vvv_hhh__yyy ___lll_" "_" T)
;  ("aaa" "vvv" "hhh" "" "yyy " "" "" "lll" "lll")
;
;  (ALE_String_ToList "aaa_vvv_hhh__yyy ___lll_" "_" nil)
;  ("aaa" "vvv" "hhh" "yyy " "lll")
;
(defun ALE_String_ToList (InpStr CarDlm TrueFl / SttPos EndPos TmpLst TmpStr)
  (setq
    CarDlm (ascii CarDlm)   SttPos 0
    EndPos (vl-string-position CarDlm InpStr)
  )
  (while EndPos
    (setq
      TmpStr (substr InpStr (1+ SttPos) (- EndPos SttPos))
      SttPos (1+ EndPos) EndPos (vl-string-position CarDlm InpStr SttPos)
    )
    (and
      (or (/= TmpStr "") TrueFl)
      (setq TmpLst (cons TmpStr TmpLst))
    )
  )
  (if (or (/= (setq TmpStr (substr InpStr (1+ SttPos))) "") TrueFl)
    (reverse (cons TmpStr TmpLst))
    (reverse TmpLst)
  )
)


andrew_nao

  • Guest
Re: function to create a list of strings
« Reply #7 on: August 20, 2014, 08:38:06 AM »
here is the code tho if anyone has need. credit to "unknown"
credit to gile (France).
http://www.theswamp.org/index.php?topic=22034.msg265916#msg265916


thanks Marc'Antonio. thats the thread i was looking for

and thanks Lee  for your post as well. i dont know why they didnt show up in the search
and thanks Gile for your code

andrew_nao

  • Guest
Re: function to create a list of strings
« Reply #8 on: August 20, 2014, 03:00:19 PM »
my title is misleading because its supposed to say create a list out of string
sorry

ronjonp

  • Needs a day job
  • Posts: 7529
Re: function to create a list of strings
« Reply #9 on: August 20, 2014, 03:11:48 PM »
my title is misleading because its supposed to say create a list out of string
sorry


You can change the title still ...

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andrew_nao

  • Guest
Re: function to create a list out of strings
« Reply #10 on: August 21, 2014, 09:05:40 AM »
done.

didnt realize that, thanks